Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Anton Makeev 
Subsystem
Maven Integration 
Affected versions
Fixed in
Fixed in build
Next build 
  • Submitted by   Dmitry Kirillov
    2 years ago (08 Apr 2008 14:05)
  • Updated by   root
    6 months ago (17 Jan 2010 19:59)
  • Jira: IDEA-43412
    (history, comments)
IDEA-43412 Maven: dependencies scope not working correctly in runtime: can not exclude module's dependency
8

Attachments

deptest.zip   (11 KB)
The maven defines several scopes for dependencies:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
There is a "provided" scope:
" This scope is only available on the compilation classpath, AND IS NOT transitive."

Here we have 2 modules in IDEA project (in attachment).
module 1 (depends on "commons-io" with scope "provided")
module 2 (depends on module 1)
In module1, IDEA shows dependency on "commons-io" with unchecked "Export" flag, so "commons-io" dependency is not shown in dependency list for module 2. This is correct.
But if we run a class with classpath "module 2", the class path contains "commons-io" dependency, like this:

[code]
C:\bin\java\jdk\jdk1.6.0_01\bin\java -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:4032,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\bin\java\jdk\jdk1.6.0_01\jre\lib\charsets.jar;....;C:\bin\java\jdk\jdk1.6.0_01\jre\lib\ext\sunpkcs11.jar;D:\temp\deptest\module2\target\classes;D:\temp\deptest\module1\target\classes;C:\Documents and Settings\dima\.m2\repository\org\apache\commons\commons-io\1.3.2\commons-io-1.3.2.jar;C:\Program Files\JetBrains\IntelliJ IDEA 7.0.3\lib\idea_rt.jar" org.test1.SomeRun
[/code]

Please note "commons-io-1.3.2.jar" is included in classpath, although it is marked as "provided" in "module 1" , so shall not be transitive.
Since I DO need to exclude "commons-io" dependency, i've added to module 2 an exclusion from module1:

[code]
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
[/code]

But it does not help either.
Module "commons-io" is included in test classpath in any case.
So we can not remove module's transitive dependency from classpath.
If we remove "module 1" from the project, transitive dependencies work fine, but in our case we do need to work with "module 1" in out project

Issue was resolved
Comments (5)
 
History
 
Linked Issues (0)
 
Anton Makeev
  Anton Makeev
10 Apr 2008 14:52
(2 years ago)
Idea builds the runtime classpath transitively regardless of the static importing structure.
That is the practical problem with such configuration?
Dmitry Kirillov
  Dmitry Kirillov
11 Apr 2008 13:39
(2 years ago)
Some times I do want to remove transitive dependency from runtime classpath.
E.g., due some limitations, we can not work with original spring-framework jars. So we modify spring framework by AspectJ. We make a new module in our IDEA project, create a pom there, an in this pom we aspectj spring-core.jar ("weave-dependency" in aspecj-maven-plugin). So this module MUST be dependent on spring-core (in pom.xml, there is a <dependency> clause, with "provided" scope), but other modules in our project can not work with original "spring-core.jar", they must depend on our AspectJ'eed module. But in IDEA we can not remove original spring-core from runtime class path. At the same time, Eclipse understands "<exclusion> clause.

Another usecase. We have 2 web-modules (and 2 pom.xml, of course). They are almost equals, they have same set of pages (e.g. .jsp files), they differ only in web.xml and are deployed in different containers, so they have different sets of libraries included. With maven, it is quite easy to achive, we make those web modules depended on each other. We can create in web-module2 dependency like this:
[pom]
 <dependency>
  <groupId>org.test1</groupId>
  <artifactId>web-module1</artifactId>
  <type>war</type>

<exclusions> list of excluded libraries here
</exclusions>
 </dependency>
[/pom]
And .war file, created from web-module2 will include all the .jsp files from webmodule1 (no need to have same .jsp file in each project).
But in IDEA this scenario can not work - when we are starting web-module2 from IDE, we have class cast exceptions, because webmodule2 can not be run, if there are dependencies from webmodule1 in classpath.

And after all, it seems to me, if we create "exclusion" clause in <dependency/>, we DO need to remove a transitive dependency :-)
There is a similar issue:
http://www.jetbrains.net/jira/browse/IDEA-17064
gui
  gui
25 Feb 2009 21:00
(17 months ago)
We are using classpath scanning to find all OSGi jar files that are on the classpath. These bundles are then installed on an embedded OSGi platform.
But this kind of code does not work the same in maven and intellij. Since intellij includes all transitive dependencies on the classpath, some OSGi bundles are picked up at runtime that should not be found.
We use this embedded OSGi platform in our unit tests. Now when the unit tests fail in maven, debugging in intellij will not help, since it uses a drasitically different classpath. Quite annoying...

Is there a good reason for this behaviour ??
Oddmar Sandvik
  Oddmar Sandvik
26 May 2009 23:12
(14 months ago)
We are having a similar problem. Attempts at excluding transitive dependencies via <exclusions> have no effect in IDEA, but work in Maven.

This has been close to a show stopper for us, since we get version conflicts on transitive dependencies from third party libraries. As a result, the application will not run in IDEA whereas it works fine when launched externally or e.g. via Maven.

This is tested on IDEA 8.1 and Maia with the same results.
Anton Makeev
  Anton Makeev
27 May 2009 14:43
(14 months ago)
It's not an easy task to fix this problem; thus, we plan to add support of runtime dependency exclusion in further eaps of Maia 9.0, so stay tuned.

Thanks,
Anton Makeev