On 27/11/2010, at 3:47 AM, frenchyan wrote:

> 
> Hello
> 
> In a multi-project environment, I have a project1 which is a java project
> defined this way:
> 
> // project1
> apply plugin: 'java'
> repositories {
>  mavenCentral()
> }
> dependencies {
>  compile 'org.json:json:20090211'
>  runtime 'log4j:log4j:1.2.16'
> }
> 
> Then I have another project (project2) which is not a java project at all
> defined this way:
> 
> // project2
> configurations {
>   lib
> }
> dependencies {
>  lib project(':project1')
> }
> Project p1 = findProject(':project1')
> task task3(dependsOn: p1.jar) << {
>  display(configurations.lib)
>  display(p1.configurations.runtime)
>  display(p1.configurations.archives)
> }
> private void display(configuration)
> {
>  println "### ${configuration}"
>  configuration.resolve()?.each {
>    println "r: ${it} => ${it.exists()}"
>  }
>  configuration.artifacts?.file?.each {
>    println "a: ${it} => ${it.exists()}"
>  }
> }
> 
> If I run 'gradle clean task3', (from the root project) I get the following
> output:
> :project1:clean
> :project1:compileJava
> :project1:processResources
> :project1:classes
> :project1:jar
> :project2:task3
> ### configuration ':project2:lib'
> r: /Users/ypujante/scratch/gradle-depend/project1/build/libs/project1.jar =>
> true
> ### configuration ':project1:runtime'
> r: /Users/ypujante/.gradle/cache/log4j/log4j/bundles/log4j-1.2.16.jar =>
> true
> r: /Users/ypujante/.gradle/cache/org.json/json/jars/json-20090211.jar =>
> true
> ### configuration ':project1:archives'
> a: /Users/ypujante/scratch/gradle-depend/project1/build/libs/project1.jar =>
> true
> 
> What I am really trying to do is the following:
> * project2 needs to have access to all the dependencies expressed in the
> 'dependencies' section (like if it was a java project)
> * in my task (in project2) I need to have access to all the jar files (the
> one produced by project1:jar as well as its compile and runtime dependencies
> and recursively) and also that it needs to obviously run the project1:jar in
> order to get the information.
> 
> I can see from the output of my task3 that I have a way to get this
> information but it seems somewhat clunky.. Also what I would like is that
> project2.configurations.lib contains the union of
> project1.configurations.runtime and project1.configurations.archives
> 
> I suppose ideally I would like my code to look like:
> configurations {
>  lib
> }
> dependencies {
>  lib project(':project1')
> }
> task task3(dependsOn: configurations.lib) << {
>  display(configurations.lib)
> }
> which would 'magically' compile project1 and make all artifacts
> (transitively/recursively) available in the lib configuration 

This is exactly what is supposed to happen.

You're running into this issue: http://jira.codehaus.org/browse/GRADLE-1236

To work around the problem, you should add maven central as a repository in 
project2.

A better solution is that we implement this issue: 
http://jira.codehaus.org/browse/GRADLE-698

Then, project2 would just inherit the repositories it needs from project1.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to