[GRADLE-1000] Use source set compile/runtime classpath for determining dependencies. Created: 22/Jun/10  Updated: 23/Jan/13  Resolved: 23/Jan/13

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Hans Dockter Assignee: Unassigned
Resolution: Incomplete Votes: 1


 Comments   
Comment by Blaine Simpson [ 02/May/11 ]

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?

Comment by Adam Murdoch [ 02/May/11 ]

Can you give us some more details of the precise control that you'd like? It might already be there.

Comment by Blaine Simpson [ 03/May/11 ]

Regarding execution sequence, that is already covered by Issue #427. I have to add distracting, superfluous tasks to use alphabetical ordering to force sequence. I don't get how a team could design and implement complex inter-project builds and such yet never have considered that there is a need to execute peer tasks in a specified order.

I'm going to rewrite the description (which was previously here) of the classpath problem with a new post, because after more testing I have learned more about the cause...

Comment by Blaine Simpson [ 04/May/11 ]

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:

: resolving dependencies :: #gra2;unspecified
        confs: [runtime]
        found commons-logging#commons-logging;1.1.1 in clientModuleChain
        found javax.servlet#jstl;1.2 in MavenRepo
:: resolution report :: resolve 305ms :: artifacts dl 0ms
        ---------------------------------------------------------------------
        |                  |            modules            ||   artifacts   |
        |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
        ---------------------------------------------------------------------
        |      runtime     |   2   |   0   |   0   |   0   ||   0   |   0   |
        ---------------------------------------------------------------------
:: resolving dependencies :: #gra2;unspecified
        confs: [altCompile]
        found commons-logging#commons-logging;1.1.1 in clientModuleChain
:: resolution report :: resolve 42ms :: artifacts dl 0ms
        ---------------------------------------------------------------------
        |                  |            modules            ||   artifacts   |
        |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
        ---------------------------------------------------------------------
        |    altCompile    |   1   |   0   |   0   |   0   ||   0   |   0   |
        ---------------------------------------------------------------------
All projects evaluated.
...
:compileJava
:: resolving dependencies :: #gra2;unspecified
        confs: [compile]
        found commons-logging#commons-logging;1.1.1 in clientModuleChain
:: resolution report :: resolve 15ms :: artifacts dl 0ms
        ---------------------------------------------------------------------
        |                  |            modules            ||   artifacts   |
        |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
        ---------------------------------------------------------------------
        |      compile     |   1   |   0   |   0   |   0   ||   0   |   0   |
        ---------------------------------------------------------------------
...
:assemble UP-TO-DATE
:run
Executing task ':run' due to:
Task ':run' has not declared any outputs.
[/home/blaine/.gradle/cache/commons-logging/commons-logging/jars/commons-logging-1.1.1.jar]

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).

Comment by Luke Daley [ 23/Jan/13 ]

It's not clear what this issue is about.

If you feel it's still an issue, please post a clarifying comment and I'll reopen it.

Generated at Wed Jun 30 11:44:20 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.