project dependencies and transitivity

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

project dependencies and transitivity

Levi Hoogenberg
Hello,

I have the following project layout:

root/
  core/
    lib/
      slf4j-api-1.5.2.jar
    src/
      main/
        java/
    build.gradle
  tests/
    lib/
      testng-5.8-jdk15.jar

    src/
      test/
        java/
    build.gradle
  build.gradle
  settings.gradle

root/build.gradle
contains:

subprojects {
  usePlugin('java')

  dependencies {
    addFlatDirResolver('lib', new File(projectDir, 'lib'))
  }

  // ...
}

project/build.gradle looks like this:

dependencies {
  compile(':slf4j-api:1.5.2@jar')
}

And finally, tests/build.gradle looks like this:

dependencies {
  testCompile project(':core'), ':testng:5.8:jdk15@jar'
}

According to section 14.7, the project dependency on core from tests makes sure that core's dependencies are added to the classpath of the tests project. Now I may misunderstand this, but I expected my test classes to be able to use SLF4J classes. When I run gradle testCompile inside tests however, I get compiler errors like the following:

cannot find symbol
symbol  : class Logger
location: package org.slf4j
import org.slf4j.Logger;
                ^

So I guess this is not what the user guide means when it says that dependencies of the other project are added to the classpath.

What would be the best way to achieve what I'm trying to do? I was kind of hoping for a setting on a dependency (whether it's exported or not), but I can't find it.

Thanks in advance and apologies for the long e-mail,
  Levi
Reply | Threaded
Open this post in threaded view
|

Re: project dependencies and transitivity

hans_d
Administrator

On Sep 27, 2008, at 2:03 PM, Levi Hoogenberg wrote:

> Hello,
>
> I have the following project layout:
>
> root/
>   core/
>     lib/
>       slf4j-api-1.5.2.jar
>     src/
>       main/
>         java/
>     build.gradle
>   tests/
>     lib/
>       testng-5.8-jdk15.jar
>     src/
>       test/
>         java/
>     build.gradle
>   build.gradle
>   settings.gradle
>
> root/build.gradle contains:
>
> subprojects {
>   usePlugin('java')
>
>   dependencies {
>     addFlatDirResolver('lib', new File(projectDir, 'lib'))
>   }
>
>   // ...
> }
>
> project/build.gradle looks like this:
>
> dependencies {
>   compile(':slf4j-api:1.5.2@jar')
> }
>
> And finally, tests/build.gradle looks like this:
>
> dependencies {
>   testCompile project(':core'), ':testng:5.8:jdk15@jar'
> }
>
> According to section 14.7, the project dependency on core from  
> tests makes sure that core's dependencies are added to the  
> classpath of the tests project. Now I may misunderstand this, but I  
> expected my test classes to be able to use SLF4J classes. When I  
> run gradle testCompile inside tests however, I get compiler errors  
> like the following:
>
> cannot find symbol
> symbol  : class Logger
> location: package org.slf4j
> import org.slf4j.Logger;
>                 ^
>
> So I guess this is not what the user guide means when it says that  
> dependencies of the other project are added to the classpath.

This is not a bug but a feature of Gradle. We explain this in detail  
in UG 12.1.2. The dependencies of the other project are added to the  
runtime classpath. We intentionally do never put transitive  
dependencies of a project or an external lib into the compile  
classpath of the using project. We consider it as best practices that  
your first level dependencies are explicitly declared. This is easy  
to change but we don't think it is a good idea.

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: project dependencies and transitivity

Levi Hoogenberg
Thanks Hans,

Nowhere did I try to imply that it was a bug :) But I do think that it would be useful to include the functionality of being able to declare that you depend on a project and its dependencies. I haven't really thought of any convincing examples (other than my standalone tests project), but if you're not keen on implementing this I could try to come up with scenarios in which it would be a good idea.

Regards,
  Levi

On Mon, Sep 29, 2008 at 11:03 AM, Hans Dockter <[hidden email]> wrote:

On Sep 27, 2008, at 2:03 PM, Levi Hoogenberg wrote:

Hello,

I have the following project layout:

root/
 core/
   lib/
     slf4j-api-1.5.2.jar
   src/
     main/
       java/
   build.gradle
 tests/
   lib/
     testng-5.8-jdk15.jar
   src/
     test/
       java/
   build.gradle
 build.gradle
 settings.gradle

root/build.gradle contains:

subprojects {
 usePlugin('java')

 dependencies {
   addFlatDirResolver('lib', new File(projectDir, 'lib'))
 }

 // ...
}

project/build.gradle looks like this:

dependencies {
 compile(':slf4j-api:1.5.2@jar')
}

And finally, tests/build.gradle looks like this:

dependencies {
 testCompile project(':core'), ':testng:5.8:jdk15@jar'
}

According to section 14.7, the project dependency on core from tests makes sure that core's dependencies are added to the classpath of the tests project. Now I may misunderstand this, but I expected my test classes to be able to use SLF4J classes. When I run gradle testCompile inside tests however, I get compiler errors like the following:

cannot find symbol
symbol  : class Logger
location: package org.slf4j
import org.slf4j.Logger;
               ^

So I guess this is not what the user guide means when it says that dependencies of the other project are added to the classpath.

This is not a bug but a feature of Gradle. We explain this in detail in UG 12.1.2. The dependencies of the other project are added to the runtime classpath. We intentionally do never put transitive dependencies of a project or an external lib into the compile classpath of the using project. We consider it as best practices that your first level dependencies are explicitly declared. This is easy to change but we don't think it is a good idea.

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: project dependencies and transitivity

hans_d
Administrator
Hi Levi,

On Sep 29, 2008, at 8:21 PM, Levi Hoogenberg wrote:

> Thanks Hans,
>
> Nowhere did I try to imply that it was a bug :) But I do think that  
> it would be useful to include the functionality of being able to  
> declare that you depend on a project and its dependencies. I  
> haven't really thought of any convincing examples (other than my  
> standalone tests project), but if you're not keen on implementing  
> this I could try to come up with scenarios in which it would be a  
> good idea.

you can achieve this already with the current Gradle.

See: http://markmail.org/message/ok2nndwtmueikfty

I wouldn't mind a good example though :)

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email