Maven 2.x Eclipse Plugin

exclude dependencies from the Classpath Container

Details

  • Number of attachments :
    1

Description

There are some dependencies that need to be in the POM in order to compile the project (e.g. javax.servlet). When I use Sysdeo's Tomcat plugin, I get an error because the servlet classes from the POM are included in the classpath via the classpath container.

Activity

Hide
Koert Zeilstra added a comment -

I have created a new option to exclude certain dependencies from the generated Eclipse classpath. The configuration option is:
<excludes>
<exclude>junit/junit</exclude>
</excludes>

The exclude contains a combination of groupId/artifactId. It would be nice to be able to specify it with the normal syntax (with groupId and artifactId elements), but I cannot see a way of doing that.

Show
Koert Zeilstra added a comment - I have created a new option to exclude certain dependencies from the generated Eclipse classpath. The configuration option is: <excludes> <exclude>junit/junit</exclude> </excludes> The exclude contains a combination of groupId/artifactId. It would be nice to be able to specify it with the normal syntax (with groupId and artifactId elements), but I cannot see a way of doing that.
Hide
Kenney Westerhof added a comment -

Those dependencies should be declared with scope=provided; those aren't currently imported in the eclipse classpath.

However, there's another issue that requests provided scoped deps to be added to the classpath since they're necessary for
compilation.

I don't think that removing the javax.servlet dependency will work here - if you have servlets defined in the project they won't compile
(not unless that tomcat plugin defines a custom library that contains it..)

Right?

Show
Kenney Westerhof added a comment - Those dependencies should be declared with scope=provided; those aren't currently imported in the eclipse classpath. However, there's another issue that requests provided scoped deps to be added to the classpath since they're necessary for compilation. I don't think that removing the javax.servlet dependency will work here - if you have servlets defined in the project they won't compile (not unless that tomcat plugin defines a custom library that contains it..) Right?
Hide
Geoffrey De Smet added a comment -

At drools they have a use case for excluded dependencies:
http://jira.jboss.com/jira/browse/JBRULES-833

The dependencies are already there throught the drools-plugin-in-eclipse which is added as a build nature.

Show
Geoffrey De Smet added a comment - At drools they have a use case for excluded dependencies: http://jira.jboss.com/jira/browse/JBRULES-833 The dependencies are already there throught the drools-plugin-in-eclipse which is added as a build nature.
Hide
Martin Goldhahn added a comment -

The scope "provided" is needed in the pom for javax.servlet. Otherwise you cannot compile the project. "provided" prevents the artifact from being included in the package. Sysdeo's Tomcat plugin uses a special classloader (DevClassLoader) to include all project dependencies in the context's classpath. Since Tomcat plugin version 3.2 beta3 the plugin contains an extended property page for the DevLoader. (The latest release is 3.2 which was relesed after beta3). The extended property page allows you to exclude certain jar files from the DevLoaders classpath. This is the place where you remove the check mark on the javax.servlet API jar file. If you use the Maven plugin for Eclipse (which is not the same as the maven plugin maven-eclipse-plugin) You also need to uncheck the Maven classpath container.

Here the short versjon:

  • in the POM: servlet-api artifact with scope provided
  • uncheck servlet-api.jar in the DevLoader's property page
Show
Martin Goldhahn added a comment - The scope "provided" is needed in the pom for javax.servlet. Otherwise you cannot compile the project. "provided" prevents the artifact from being included in the package. Sysdeo's Tomcat plugin uses a special classloader (DevClassLoader) to include all project dependencies in the context's classpath. Since Tomcat plugin version 3.2 beta3 the plugin contains an extended property page for the DevLoader. (The latest release is 3.2 which was relesed after beta3). The extended property page allows you to exclude certain jar files from the DevLoaders classpath. This is the place where you remove the check mark on the javax.servlet API jar file. If you use the Maven plugin for Eclipse (which is not the same as the maven plugin maven-eclipse-plugin) You also need to uncheck the Maven classpath container. Here the short versjon:
  • in the POM: servlet-api artifact with scope provided
  • uncheck servlet-api.jar in the DevLoader's property page
Hide
Geoffrey De Smet added a comment -

Putting them on scope "provided" won't work in the drools use case though - they need to be able to exclude them as the drools build nature already adds them.

Show
Geoffrey De Smet added a comment - Putting them on scope "provided" won't work in the drools use case though - they need to be able to exclude them as the drools build nature already adds them.
Hide
Hugh Willson added a comment -

I agree, I think <exclude> functionality would be a big help. I've encountered this problem in another way, and that is working with MyEclipse and JBoss.

To be able to build my web apps successfully with Maven alone, I make reference to the needed Java EE api's with provided scope. When I run mvn eclipse:eclipse to work with MyEclipse however, I've added additional <classpathContainer> settings for MyEclipse's "com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER". This means within MyEclipse, my application has a reference to the needed JEE classes from MyEclipse's container settings, and from my "provided" scope JEE dependencies. Not a huge problem, until I use MyEclipse's integration with JBoss. JBoss 4.2.0 with blow up because the JEE dependencies are deployed with the app to JBoss from MyEclipse (whereas MyEclipse J2EE14_CONTAINER isn't, as MyEclipse knows not to do this).

So, to sum up - our production builds are created using a continuous integration server with Maven, meaning the JEE dependencies have to be made available with our app, but having this dependency added to the .classpath file for MyEclipse use actually gets in the way of MyEclipse's custom com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER. All of this could be avoided with some kind of dependency exclusion filter when generating the .classpath file (similiar to the patch supplied). This way Maven can keep the dependencies it needs, but Eclipse dependency use can be modified when needed.

Thanks very much!

Show
Hugh Willson added a comment - I agree, I think <exclude> functionality would be a big help. I've encountered this problem in another way, and that is working with MyEclipse and JBoss. To be able to build my web apps successfully with Maven alone, I make reference to the needed Java EE api's with provided scope. When I run mvn eclipse:eclipse to work with MyEclipse however, I've added additional <classpathContainer> settings for MyEclipse's "com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER". This means within MyEclipse, my application has a reference to the needed JEE classes from MyEclipse's container settings, and from my "provided" scope JEE dependencies. Not a huge problem, until I use MyEclipse's integration with JBoss. JBoss 4.2.0 with blow up because the JEE dependencies are deployed with the app to JBoss from MyEclipse (whereas MyEclipse J2EE14_CONTAINER isn't, as MyEclipse knows not to do this). So, to sum up - our production builds are created using a continuous integration server with Maven, meaning the JEE dependencies have to be made available with our app, but having this dependency added to the .classpath file for MyEclipse use actually gets in the way of MyEclipse's custom com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER. All of this could be avoided with some kind of dependency exclusion filter when generating the .classpath file (similiar to the patch supplied). This way Maven can keep the dependencies it needs, but Eclipse dependency use can be modified when needed. Thanks very much!
Hide
nicolas de loof added a comment -

patch applied with minor change :

groupId artifactId separator changed to ":" as this is the conventions used by other maven plugins (maven-assembly-plugin for example) :

<excludes>
<exclude>junit:junit</exclude>
</excludes>

Show
nicolas de loof added a comment - patch applied with minor change : groupId artifactId separator changed to ":" as this is the conventions used by other maven plugins (maven-assembly-plugin for example) : <excludes> <exclude>junit:junit</exclude> </excludes>
Hide
Tom Bollwitt added a comment - - edited

would it be possible to add the ability to exclude all dependencies? We are using the Maven Eclipse plugin (http://m2eclipse.sonatype.org/update/) and when adding...
<additionalProjectnatures>
<projectnature>
org.maven.ide.eclipse.maven2Nature
</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
</buildCommand>
</additionalBuildcommands>

causes there to be duplicate classpath entries for the dependencies since all the M2_REPO variables are added to the classpath.
I checked out the code and changed line 601 in AbstractIdeSupportMojo
FROM:
if ( getExcludes().contains( artifactFullId ))
TO:
if ( getExcludes().contains( artifactFullId ) || getExcludes().contains( "*:*" ))

I then just added to the pom...
<excludes>
<exclude>*:*</exclude>
</excludes>

This worked for what I needed and just thought that others may benefit from it.

Show
Tom Bollwitt added a comment - - edited would it be possible to add the ability to exclude all dependencies? We are using the Maven Eclipse plugin (http://m2eclipse.sonatype.org/update/) and when adding... <additionalProjectnatures> <projectnature> org.maven.ide.eclipse.maven2Nature </projectnature> </additionalProjectnatures> <additionalBuildcommands> <buildCommand> <name>org.maven.ide.eclipse.maven2Builder</name> </buildCommand> </additionalBuildcommands> causes there to be duplicate classpath entries for the dependencies since all the M2_REPO variables are added to the classpath. I checked out the code and changed line 601 in AbstractIdeSupportMojo FROM: if ( getExcludes().contains( artifactFullId )) TO: if ( getExcludes().contains( artifactFullId ) || getExcludes().contains( "*:*" )) I then just added to the pom... <excludes> <exclude>*:*</exclude> </excludes> This worked for what I needed and just thought that others may benefit from it.
Hide
Arnaud Heritier added a comment -

you have an eclipse:m2eclipse goal to be compatible this eclipse plugin

Show
Arnaud Heritier added a comment - you have an eclipse:m2eclipse goal to be compatible this eclipse plugin
Hide
Tom Bollwitt added a comment -

Thanks Amaud!
I am not sure why I did not notice that goal before.

Show
Tom Bollwitt added a comment - Thanks Amaud! I am not sure why I did not notice that goal before.
Hide
Maarten Billemont added a comment -

This does not appear to prevent the dependencies from being downloaded.

Show
Maarten Billemont added a comment - This does not appear to prevent the dependencies from being downloaded.

People

Vote (19)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: