I understand that Gradle automatically adds compile dependencies onto the runtime classpath. Though I hate this behavior (I specified "compile" classpath, not "compile + runtime" classpath), it is understandable.
What I don't understand is why the dependencies that I am setting for my custom source set ("altRuntime") is clobbering my plain "runtime" dependency.
defaultTasks 'run'
...
configurations { compile { transitive = false } }
configurations { altCompile { transitive = false } }
configurations { altRuntime { transitive = false } }
configurations { runtime { transitive = false } }
dependencies {
compile(
[group: 'commons-logging', name: 'commons-logging', version: '1.1.1'],
)
altCompile (
[group: 'commons-logging', name: 'commons-logging', version: '1.1.1'],
)
altRuntime (
[group: 'commons-logging', name: 'commons-logging', version: '1.1.1']
)
runtime(
'javax.servlet:jstl:1.2:jar'
)
}
sourceSets {
alt {
compileClasspath = configurations.altCompile
runtimeClasspath = configurations.altRuntime
}
}
...
task run (dependsOn: assemble) << {
String jarPath = relativePath(new File(libsDir, archivesBaseName + ".jar"))
println configurations.runtime.files
Output from gradle -i:
See that though I set the runtime dependency to the jstl jar file, Gradle sets my runtime classpath to the commons logging jar file. (I found by changing things that the problem goes away if I remove the alt settings, so I think Gradle is treating the altRuntime dep or classpath value is my plain runtime value).
Gradle dependencies are crazy. For a build system to be adequate for professional usage, it needs to at least allow for precise control over sequence of task executions, and precise control over classpaths. At this point in time, Gradle has neither.
Compile classpaths bleed over to the runtime classpath when using java plugin. War plugin classpaths are at least usable but the rules are idiosyncratic. Why not just leverage Ivy and have predefined Ivy configs mirroring runtime names so the user can directly specify what they want for build time and for bundle and/or runtime?