kppk
kppk

Reputation: 52

Gradle war ignores transitive dependencies when using 'configurations.runtime.asPath' in custom task

I'm facing behavior that I can't explain, using gradle 1.10 I have:

settings.gradle:

include('lib1', 'lib2', 'web')

build.gradle:

subprojects {
  apply plugin: 'java'
}

project(':web') {
  apply plugin: 'war'
  dependencies {
    compile project(':lib1')
  }

  task myTask(type: JavaExec, dependsOn: 'compileJava') {
        main = "some.thirdparty.Class"
        args "--searchPath", configurations.runtime.asPath
  }

}

project(':lib1') {
  dependencies {
    compile project(':lib2')
  }
}

project(':lib2') {
}

When I run gradle clean war I only have lib1.jar in war/build/libs/web.war/WEB-INF/lib.

To make WEB-INF/lib contain both lib1.jar and lib2.jar I have to:

I read the build lifecycle description, tried to compare --debug outputs but that didn't help.

Why is this happening? And what would be a good solution to provide the module runtime class path as a path in JavaExec task please?

Upvotes: 1

Views: 782

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

asPath resolves the configuration, but resolution will only work correctly if it happens at execution time rather than configuration time (in particular in the presence of project dependencies). Try to wrap the args line with doFirst { ... }.

Upvotes: 2

Related Questions