Coming Up for Air

Gradle Tip: Seeing Standard Streams During Tests

Jason Lee 2013-09-10

I'm not a real big fan of using standard out as a debugging strategy (I prefer an IDE and break points, for what it's worth), but there are times when it's either necessary or just convenient. The standard Gradle configuration, though, makes this a bit more difficult than it probably should be. Fortunately, Gradle also makes it easy to change:

test {
    testLogging.showStandardStreams = true
}

If you'd like to make this change globally, that's also easy:

allprojects {
    tasks.withType(Test) {
        testLogging.showStandardStreams = true
    }
}

Filtering Mail using JavaMail

Jason Lee 2013-09-04

At the Lee House, we have an email problem: there's just too much of it. Over the years of signing up for contests, coupons, and other things, we seem to have amassed a giant number of subscriptions to various lists, which gives us a lot of (usually) junk email. The simple solution, of course, is just to unsubscribe, but some of those are actually occasionally useful. Throw in a pinch of proscratination and laziness, and, well... it all just keeps coming. Email clients can help manage this by providing email filters to move these emails out of the inbox, but, in the case of Thunderbird, there are only so many rules you can add to one filter, so you either create multiple rules, or give up trying. Several months back, I moved these rules to a perl-based system, but, thanks to a hard drive crash, I lost all of those. Rather than rebuild that setup, which had its own limitations, I did what every good geek would do: I wrote my own, and here it is. :)

Building "Fat Jars " with Gradle

Jason Lee 2013-09-04

Sometimes, such as when building command line Java apps, it would be nice to bundle all of the app's dependencies in a single jar so that the user need not collect and manage these. With Gradle, that can be easily accomplished with the following lines:

jar {
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
}

When you run gradle assemble, you should find your now very hefty jar in build/libs.

WebJars and JSF

Jason Lee 2013-08-28

WebJars , for those that haven't heard, is a project that takes popular client-side web libraries and packages them in JARs to make their use in Java-/JVM-based web apps simpler. The web site notes that you can easily see which libraries a project is using simply by looking at its dependencies, and that transitive dependencies automatically appear. It's a pretty compelling project, but, for some reason, it doesn't show how to integrate it with JSF. I'd like to think it's because it's so trivial, but I'll show it here anyway. :)

A Quick-start for Scala and Gradle

Jason Lee 2013-08-22

For those interested, here's a quick and simple project to get you started using Gradle and Scala together:

apply plugin: 'scala'

repositories{
    mavenCentral()
    mavenLocal()
}

dependencies{
    compile 'org.slf4j:slf4j-api:1.7.5'
    compile "org.scala-lang:scala-library:2.10.1"
    testCompile "junit:junit:4.11"
}

task run(type: JavaExec, dependsOn: classes) {
    main = 'Main'
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime
}
object Main extends App {
  println("Hello, world")
}

You can run the app using the custom task run:

$ gradle run
:compileJava
:compileScala
:processResources
:classes
:run
Hello, world

BUILD SUCCESSFUL

Total time: 9.79 secs

Remember to add --daemon for faster startup times for your Gradle builds.

Have fun!

Search

Quotes

Sample quote

Quote source

About

My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

My Links

Publications