The maven defines several scopes for dependencies:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_ScopeThere 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
That is the practical problem with such configuration?
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
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 ??
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.
Thanks,
Anton Makeev