Maven vs. Gradle Difference on Dependencies

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

Maven vs. Gradle Difference on Dependencies

Ken Sipe
I'm looking to move over my projects for spring to gradle... I pulled down a sample mvn project and was in the process of converting it and got some interesting results that I hope someone on the forum understands...

The list of dependencies for maven (as shown below) only has 2 references to the spring framework, It pulls all the other dependencies without the need to be explicit.  When creating a gradle build (second listing below), it was necessary to explicitly list each dependency... what gives?    Is there something I'm missing?

** mvn pom.xml file> **
 <build>
  <finalName>hello</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
 
  <repositories>
   <repository>
    <id>springsource maven repo</id>
    <url>http://maven.springframework.org/milestone</url>
   </repository>
  </repositories>
 
  <dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.0.0.RC2</version>
   </dependency>
   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>3.0.0.RC2</version>
    <scope>test</scope>
   </dependency>
   <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.7</version>
    <scope>test</scope>
   </dependency>
   <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
   </dependency>
   <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
   </dependency>
   <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
    <scope>provided</scope>
   </dependency>
  </dependencies>

** gradle build file **
usePlugin 'java'
usePlugin 'war'

repositories {
        mavenCentral()
        mavenRepo urls: 'http://maven.springframework.org/milestone'       
}

dependencies {
       
        compile 'org.springframework:spring-webmvc:3.0.0.RC2'
        compile 'org.springframework:spring-web:3.0.0.RC2'
        compile 'org.springframework:spring-context:3.0.0.RC2'
       
        testCompile 'org.springframework:spring-test:3.0.0.RC2'
        testCompile 'junit:junit:4.7'
}
Reply | Threaded
Open this post in threaded view
|

Re: Maven vs. Gradle Difference on Dependencies

hans_d
Administrator

On Nov 19, 2009, at 8:21 AM, kensipe wrote:

>
> I'm looking to move over my projects for spring to gradle... I pulled down a
> sample mvn project and was in the process of converting it and got some
> interesting results that I hope someone on the forum understands...
>
> The list of dependencies for maven (as shown below) only has 2 references to
> the spring framework, It pulls all the other dependencies without the need
> to be explicit.  When creating a gradle build (second listing below), it was
> necessary to explicitly list each dependency... what gives?    Is there
> something I'm missing?

I'm not hundred percent sure, but I guess the issue is that Gradle by default uses only first level dependencies for compiling. That way Gradle checks, that all external dependencies used directly in your code are explicitly declared.

Just add the following task:

task show << {
    println configurations.compile.files
    println configurations.runtime.files
    println configurations.testCompile.files
    println configurations.testRuntime.files
}

You will see that runtime (which is for example used by the tests) contains also the transitive dependencies.

To change this behavior you can say:

configurations {
   compile.transitive = true
}

- Hans

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

<snip>

>
> ** gradle build file **
> usePlugin 'java'
> usePlugin 'war'
>
> repositories {
> mavenCentral()
> mavenRepo urls: 'http://maven.springframework.org/milestone'       
> }
>
> dependencies {
>
> compile 'org.springframework:spring-webmvc:3.0.0.RC2'
> compile 'org.springframework:spring-web:3.0.0.RC2'
> compile 'org.springframework:spring-context:3.0.0.RC2'
>
> testCompile 'org.springframework:spring-test:3.0.0.RC2'
> testCompile 'junit:junit:4.7'
> }



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Maven vs. Gradle Difference on Dependencies

Ken Sipe
That's great... and thanks for the leg up... I think I found a bug however.

making the change as recommended didn't help... and it seemed strange. after a little R&D,  I deleted my cache (manually "rm -rF cache") and then the change worked fine.  So it appears that if you bring down dependencies once... after a change in the build file which requests a different approach, the cache isn't updated... it seems to realize that the first dependency is there, without a knowledge of other dependencies it just fails.  This seems like a bug.

Also the original gradle show (from the code you replied with), showed one jar.. the webmvc jar.  After I downloaded all the dependences (after deleting my cache and had the configurations.compile.transitive = true), then the gradle show had a large number of jars for the runtime.  If I turned the configurations.compile.transitive = false or commented it out (supposedly back to the default), then I still got all the dependency jars.   So you get what is ever in the cache... you get what ever you requested the first time you run the build script regardless of what you change the build file afterward.
Hopefully that makes sense... ping me if you want more detail or you need it written up for a bug report.

In the end, I got it working and I understand your answer... also I think I like being more explicit.  The number of jars coming down was high relative to my need.  Which basically means I agree with the user guide.

Thanks!

hdockter wrote
On Nov 19, 2009, at 8:21 AM, kensipe wrote:

>
> I'm looking to move over my projects for spring to gradle... I pulled down a
> sample mvn project and was in the process of converting it and got some
> interesting results that I hope someone on the forum understands...
>
> The list of dependencies for maven (as shown below) only has 2 references to
> the spring framework, It pulls all the other dependencies without the need
> to be explicit.  When creating a gradle build (second listing below), it was
> necessary to explicitly list each dependency... what gives?    Is there
> something I'm missing?

I'm not hundred percent sure, but I guess the issue is that Gradle by default uses only first level dependencies for compiling. That way Gradle checks, that all external dependencies used directly in your code are explicitly declared.

Just add the following task:

task show << {
    println configurations.compile.files
    println configurations.runtime.files
    println configurations.testCompile.files
    println configurations.testRuntime.files
}

You will see that runtime (which is for example used by the tests) contains also the transitive dependencies.

To change this behavior you can say:

configurations {
   compile.transitive = true
}

- Hans

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

<snip>

>
> ** gradle build file **
> usePlugin 'java'
> usePlugin 'war'
>
> repositories {
> mavenCentral()
> mavenRepo urls: 'http://maven.springframework.org/milestone'       
> }
>
> dependencies {
>
> compile 'org.springframework:spring-webmvc:3.0.0.RC2'
> compile 'org.springframework:spring-web:3.0.0.RC2'
> compile 'org.springframework:spring-context:3.0.0.RC2'
>
> testCompile 'org.springframework:spring-test:3.0.0.RC2'
> testCompile 'junit:junit:4.7'
> }



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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Maven vs. Gradle Difference on Dependencies

hans_d
Administrator

On Nov 20, 2009, at 2:55 AM, kensipe wrote:

>
> That's great... and thanks for the leg up... I think I found a bug however.
>
> making the change as recommended didn't help... and it seemed strange. after
> a little R&D,  I deleted my cache (manually "rm -rF cache") and then the
> change worked fine.  So it appears that if you bring down dependencies
> once... after a change in the build file which requests a different
> approach, the cache isn't updated... it seems to realize that the first
> dependency is there, without a knowledge of other dependencies it just
> fails.  This seems like a bug.
>
> Also the original gradle show (from the code you replied with), showed one
> jar.. the webmvc jar.  After I downloaded all the dependences (after
> deleting my cache and had the configurations.compile.transitive = true),
> then the gradle show had a large number of jars for the runtime.  If I
> turned the configurations.compile.transitive = false or commented it out
> (supposedly back to the default), then I still got all the dependency jars.  
> So you get what is ever in the cache... you get what ever you requested the
> first time you run the build script regardless of what you change the build
> file afterward.
> Hopefully that makes sense... ping me if you want more detail or you need it
> written up for a bug report.

I can't reproduce this behavior. If I use the test script attached to the issue and I run it with compile.transitive=true the right stuff is shown. If I change it to false only first level dependencies are shown. I can switch it on and off and everything works.

The fact that -C rebuild make it work for you points out that this is not an issue with the dependency cache. It looks like an issue with the cached build script. To improve startup time performance Gradle saves the compiled build script. If it has not changed we use the compiled version from the cache. It looks as if for some reason your change to the build script is not picked up and the old version from the cache is used. But that would apply to any modification you are applying to the build script. So what happens if you change the transitive state and do some other modification. Is the latter picked up but not the first?

- Hans

--
Hans Dockter
Gradle Project Manager
http://www.gradle.org
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email