History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-17666
Type: Bug Bug
Status: Open Open
Assignee: Anton Makeev
Reporter: Dmitry Kirillov
Votes: 3
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Maven dependencies scope not working correctly: can not exclude module's dependency

Created: 08 Apr 08 14:05   Updated: 11 Apr 08 15:07
Component/s: Maven Integration

File Attachments: 1. Zip Archive deptest.zip (11 kb)

Issue Links:
Duplicate
 
This issue is duplicated by:
IDEA-17064 IDEA does not handle <optional> depen... Closed

Build: 7,757


 Description  « Hide
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



 All   Comments   Work Log   Change History      Sort Order:
Anton Makeev - 10 Apr 08 14:52
Idea builds the runtime classpath transitively regardless of the static importing structure.
That is the practical problem with such configuration?

Dmitry Kirillov - 11 Apr 08 13:39
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