This repository has been created as a reproduction case to support a Gradle forum question.
The crux of the question is:
Why doesn't Gradle download transitive dependencies when a file extension e.g.
@jar
is specified on a dependency?
This is demonstrated as follows:
- Clone this repository.
- Run
./gradlew test
. The task will fail with a compilation error becausejavaposse.jobdsl.dsl.JobManagement
is not available on the test compilation classpath. - Uncomment line
59
inbuild.gradle
- Run
./gradlew test
again. This time compilation will succeed and theBasicSpec
test will pass. - Help me understand why this happens?
javaposse.jobdsl.dsl.JobManagement
resides in theorg.jenkins-ci.plugins:job-dsl-core
dependency, which is a transitive dependency of theorg.jenkins-ci.plugins:job-dsl
dependency.- The
packaging
element in theorg.jenkins-ci.plugins:job-dsl
pom.xml is set tohpi
. If we declare this dependency astestImplementation "org.jenkins-ci.plugins:job-dsl:${jobDslVersion}"
then Gradle will also download all of its transitive dependencies (which includejob-dsl-core
) and will add them to the relevant classpath. - However, I specifically want the
jar
artefact ofjob-dsl
, as it contains classes that I want to use. When thehpi
artefact gets pulled in those classes are unavailable to me. - I can obtain the
jar
artefact ofjob-dsl
by specifying@jar
as the extension. When I do this Gradle downloads thejar
artefact, however it also then no longer downloads any of the transitive dependencies. - The only solution I can think of is to then explicitly depend on each of the, now absent, transitive dependencies. However this feels wrong and brittle.
- Question: Is there a way I can tell Gradle to download the
job-dsl
jar
artefact and to also download all of its transitive dependencies?
Very grateful for any help on this one!
- The initial problem is demonstrated in commit ec26bbfcee8b8deac1ffee55b743ce8813d5ad22.
- The solution that I came up with in the end is in commit 147cb86cd2487b642275ac1d66174782ad8568e8. This was inspired from help received on the Gradle forum here