Tuesday, July 2, 2013

Some tips/tricks with gradle builds

Blog post is under construction ...

Dependencies


Understanding dependencies ...

./gradlew -q acmeair-webapp:dependencyInsight --dependency javax.servlet

I looked at the output and then saw the exact package it was bringing in:

org.eclipse.jetty.orbit:javax.servlet:2.5.0.v201103041518

And added this to providedRuntimes in my packaging:


providedRuntime 'org.eclipse.jetty.orbit:javax.servlet:2.5.0.v201103041518'

And finally, the specific jar was gone from my war

By adding something to the providedRuntime, you can break things as this instructs the packager to treat the runtime and its dependencies as not required.  I ran into the issue when I told it not to include aws-java-sdk which depends on commons-logging-1.1.1.  Without being more specific, I ran into Spring not starting with the infamous error which was actually this.

You can be more specific in exclusion by adding .jar like:


providedRuntime 'com.amazonaws:aws-java-sdk:1.3.27@jar'

Plugins


Using the application plugin

To use the application plugin here are all four steps for getting it to work with arguments in a multi-project build:

project(':somesubproject') {
  apply plugin: 'application'
  mainClassName = 'org.spyker.MainClass'
  run {
    args = ['someargument', 'asecondargument]
  }
}

./gradlew :somesubproject:run

Notes:  If you only have a single argument remember to put it in an array args = ['singlearg'].  I eventually need to find out how to pass in args via a -P parameter.

3 comments:

  1. Nice! Thank you! I was missing the `:somesubproject:run` part. I was running it from main project.

    ReplyDelete
  2. If you need your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (even if they're dating somebody else now) you got to watch this video
    right away...

    (VIDEO) Have your ex CRAWLING back to you...?

    ReplyDelete