[GRADLE-900] If a configuration is set to transitive = false, the transitive attribute of a dependency is ignored. Created: 11/Apr/10  Updated: 10/Feb/17  Resolved: 10/Feb/17

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

Type: Bug
Reporter: Steven Devijver Assignee: Unassigned
Resolution: Won't Fix Votes: 2

Attachments: Zip Archive gradle-problem.zip     Zip Archive jdepend-bcel.zip    

 Description   

INFO: I'm using 0.9 preview 1!!

Attached project fails to build with this transitive dependency:

compile ("org.mortbay.jetty:jetty:6.1.22")

{ transitive = true }

I get this error for 'gradle clean build':

C:\dev\gradle-problem>gradle clean build
:clean UP-TO-DATE
:compileJavaC:\dev\gradle-problem\src\main\java\JettyServer.java:9: cannot acces
s org.mortbay.component.AbstractLifeCycle
file org\mortbay\component\AbstractLifeCycle.class not found
Server jetty = new Server(8888);
^
C:\dev\gradle-problem\src\main\java\JettyServer.java:13: cannot find symbol
symbol : method start()
location: class org.mortbay.jetty.Server
jetty.start();
^
2 errors
:compileJava

FAILURE: Build failed with an exception.

  • Where:
    Build file 'C:\dev\gradle-problem\build.gradle'
  • What went wrong:
    Execution failed for task ':compileJava'.
    Cause: Compile failed; see the compiler error output for details.
  • Try:
    Run with -s or -d option to get more details. Run with -S option to get the full
    (very verbose) stacktrace.

BUILD FAILED

Total time: 6.313 secs

Which, I must say, is a pretty strange compile error.

When I declare the dependencies in a non-transitive way the compilation succeeds:

compile "org.mortbay.jetty:jetty:6.1.22"
compile "org.mortbay.jetty:jetty-util:6.1.22"
compile "org.mortbay.jetty:servlet-api:2.5-20081211"

Also, with the transitive dependency 'gradle eclipse' works just fine.



 Comments   
Comment by Hans Dockter [ 12/Apr/10 ]

We are aware of this problem. The underlying Ivy behavior is kind of surprising. If an ivy configuration sets transitive to false, a transitive=true of a dependency is ignored. What Gradle should do to solve this, is to set an ivy configuration transitive value always to true. The Gradle configuration transitive value will then be just the default value for the transitive value of the dependencies. Which can be overridden as in the case above.

In fact this even points to some other problem. We have the policy that the compile configuration resolves non-transitively. I think the objective behind this is still valid. But for example for Groovy code this does not work as Groovy also needs the transitive dependencies in the classpath for compiling. With Jetty the same seems to be the case. I would be interested how this can be the case for a Java project. Therefore I think we should change our strategy. compile should resolve transitively but the code-quality check should spit our warnings or make the build fail, if transitive dependencies are directly used in the source code.

Comment by Steven Devijver [ 12/Apr/10 ]

Ok, I see what you're saying. You're saying that because of the way Jetty is packaged the compiler will fail if the class hierarchy is not entirely present on the classpath.

Actually, I think that when a dependency is explicitly declared as transitive gradle should accept this at compile time. The user may not know what he or she is doing but it's not reasonable to assume gradle can fix that problem.

About the code-quality checks, this is probably a good idea. If I want to compile against classes I should explicitly import all the jars I need. Actually, I'm pretty sure you can do this with BCEL after compilation so that this check could become part of gradle. I've recently implemented an import checker based on this article and it worked like a charm:

http://illegalargumentexception.blogspot.com/2008/04/java-finding-binary-class-dependencies.html

Comment by Steven Devijver [ 12/Apr/10 ]

I've factored out the jdepend/bcel code I wrote recently which could form the basis of a gradle plugin.

To give you an idea of what it does, here's some output:

Seen poc.jdepend.visitor.JDependWalker
poc.jdepend.visitor.JDependWalker extends java.lang.Object
poc.jdepend.visitor.JDependWalker imports poc.jdepend.visitor.JDependWalker
poc.jdepend.visitor.JDependWalker imports java.lang.Object
poc.jdepend.visitor.JDependWalker imports java.io.IOException
poc.jdepend.visitor.JDependWalker imports jdepend.framework.JDepend
poc.jdepend.visitor.JDependWalker imports java.util.Collection
poc.jdepend.visitor.JDependWalker imports java.util.Iterator
poc.jdepend.visitor.JDependWalker imports jdepend.framework.JavaPackage
poc.jdepend.visitor.JDependWalker imports jdepend.framework.JavaClass
poc.jdepend.visitor.JDependWalker imports poc.jdepend.visitor.ClassVisitor
poc.jdepend.visitor.JDependWalker imports java.lang.String
poc.jdepend.visitor.JDependWalker imports java.util.ArrayList
poc.jdepend.visitor.JDependWalker imports org.apache.bcel.Repository
poc.jdepend.visitor.JDependWalker imports poc.jdepend.visitor.JDependWalker$1DependencyEmitter
poc.jdepend.visitor.JDependWalker imports org.apache.bcel.classfile.DescendingVisitor
poc.jdepend.visitor.JDependWalker imports java.util.Collections
poc.jdepend.visitor.JDependWalker imports org.apache.bcel.classfile.JavaClass
Seen poc.jdepend.visitor.ClassVisitor
poc.jdepend.visitor.ClassVisitor extends java.lang.Object
poc.jdepend.visitor.ClassVisitor imports poc.jdepend.visitor.ClassVisitor
poc.jdepend.visitor.ClassVisitor imports java.lang.Object

Comment by Hans Dockter [ 22/Apr/10 ]

Hi Steven, I thought I had already commented on that. But I can't find it. Having such a plugin would be very cool. Could you create something like a GitHub project with the stuff you extracted from jdepend?

Comment by Hans Dockter [ 22/Apr/10 ]

The compile configuration is now resolved transitively by default. So your Jetty stuff will just work now.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

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