Exclude test for some projects - java

Sorry Im newbie in Java and I wonder how to avoid test execution of my dependencies projects.
I have a Proj3 which has two dependencies, Proj1 and Proj2 (among other things).
If I execute mvn clean install not only execute tests of my current Proj3 but also from my dependencies Proj1 and Proj2.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.proj.environment.tests.api</groupId>
<artifactId>environment_Api_Tests</artifactId>
<version>437r21</version>
<packaging>pom</packaging>
<properties>
<cucumber.version>4.3.1</cucumber.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.version>437r21</project.version>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.proj.environment</groupId>
<artifactId>Proj1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.proj.environment</groupId>
<artifactId>Proj2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<exclude>**/*Test.java</exclude>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../Proj1</module>
<module>../Proj2</module>
</modules>
Many thanks,

The POM you are showing is for environment_Api_Tests project which is aggregation (parent) project. That means
... if a Maven command is invoked against the parent project, that Maven command will then be executed to the parent's modules as well.
Thus it is not very clear what exactly is your case.
Depending on what it has to do with the Proj3 you mentioned, there are different answers:
If the environment_Api_Tests project (the POM you posted) is what you call Proj3
It is perfectly normal to execute commands against its modules (do not confuse it with dependencies) and it really makes no sense to exclude tests from modules. Moreover you can not have tests in aggregation (parent) project itself. So if you only want to execute some modules, then it's best to introduce another aggregation project with only those modules. You can further aggregate aggregation projects.
The <dependencies> here have nothing to do with that. The only thing that section does in a aggregation project is to provide dependencies for all <modules>. In your case that means that:
Proj1 depends on Proj1 and Proj2.
Proj2 depends on Proj1 and Proj2.
which is probably not what you want!
If there is another Proj3 that is also a module in environment_Api_Tests
Then you just need to execute the tests on that project and not on environment_Api_Tests. Even if Proj3 depends on Proj1 and Proj2 their tests will not be executed
If Proj3 is environment_Api_Tests but it was not meant to be an aggregation project
Then you need to change the packaging from pom to jar (or whatever your target is) and remove the <modules> but keep the <dependencies>. That way the project can have own tests and will not execute tests of dependencies.
Note on test dependencies
One thing to keep in mind is how test dependencies work in multi-module projects. If tests in one module depends on tests in another module, you will have to create a jar containing test classes.

Related

using super pom only for testing

I have a lot of maven projects, which are dependent on each other.
I already have a super pom for the actual projects and this works pretty well.
Now I want to create a super pom for all my integrationtests projects. I did it the same, but every time I run maven test it failed.
[ERROR] Failed to execute goal on project *: Could not resolve
dependencies for project ::jar:0.0.1-SNAPSHOT: The following
artifacts could not be resolved: ::jar:0.0.1-SNAPSHOT,
::jar:0.0.1-SNAPSHOT, ::jar:0.0.1-SNAPSHOT, ::jar:0.0.1-SNAPSHOT: Could not find artifact *:***:jar:0.0.1-SNAPSHOT -> [Help 1]
The problem is that maven looks for jar files but my project consists of war projects. Here is my pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***</groupId>
<artifactId>***-parent_IntegrationTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>***_IntegrationTests</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>../***</module>
<module>../***</module>
<module>../***</module>
<module>../***</module>
<module>../***</module>
<module>../***</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
Is there a way to tell maven to use the war files instead of jars?
Edit: Sorry if it is not clear enough. I want a single maven project to run all my integrationtest projects. each one is a maven project. Therefor I want to use a pom with modules (all the integrationtest project) in it. But every integrationtest project contains dependencies to my other projects and the problem I want to fix is that maven does not find my compiled projects because it looks for jar files but my projects are war files.
You can reference WARs as dependencies by using <type>war</type> in the dependency.

Identifying the Test Directories in a Java Maven Project

I have not followed the general Maven project structure in my Project. This is how my project structure looks like -
ProjectName
|- src
|- app
|- models
|- services
|- test
|- unit
|- services
|- integration
|- services
For the test I am using Junit and Mockito. My pom.xml file looks like this -
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProjectName</groupId>
<artifactId>ProjectName</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The problem that I am facing now is, when I am running my tests it is not able to find the dependency packages junit and mockito. I know it is because I have declared the scope of these dependecies as test.
What I want to know is, what change should I make in my pom.xml file so that Maven can indentify my test directory?
The Maven surefire plugin will look for tests in the directory the property project.build.testSourceDirectory is pointing to.
So you can add this to your pom.xml to change the value of this property:
<build>
<testSourceDirectory>${project.basedir}/src/test</testSourceDirectory>
</build>
This will execute all tests (unit and integration) in the test phase. If you dont want to execute the integration tests, you can set the property to ${project.basedir}/src/test/unit.
I would also suggest to follow the conventions for maven projects as others did.
Still, things should work by overriding following maven properties as below:
<properties>
<!-- Considering src/app will have all your sourcr java code -->
<project.build.sourceDirectory>src/app</project.build.sourceDirectory>
<!-- Considering all your junit tests are in src/test/unit -->
<project.build.testSourceDirectory>src/test/unit</project.build.testSourceDirectory>
...
</properties>
If you want to add integration test with maven, then I would suggest to go over this article.
You can remove <sourceDirectory> and <resources> from <build> section.

How to include all modules from pom project

I am looking for a way to include all the modules in a project from another pom.xml. So in my case I have a parent pom with packaging set to pom. It contains 3 child modules that implement my interfaces in another api module. I want to dynamically include all the child modules in my project in maven.
In this case I want to include the connector1, connector2, connector3 in another module without having to specifiy the connector1,2,3 implicitly.
connectors - packaging: pom
connector1 - packaging: jar
connector2 - packaging: jar
connector3 - packaging: jar
I tried including the connectors pom in my project but this did not work. I was hoping that specifying the parent package with pom would include the child modules but this did not work. Are there any workarounds for how to do this?
Update
This was more of peeve of mine because I wanted to simply add a single connector and have all the child module dependency jars for the project be included. This would make the pom a little simpler to read.
Instead of having to register all the child dependencies like so
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-api</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-etl</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-persistence</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-api</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-etl</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-persistence</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-other</artifactId>
<version>0.0.1</version>
</dependency>
...
</dependencies>
This is just an example to clarify the original question. It does not exist and would probably have reprocussions if it did work.
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1</artifactId>
<version>0.0.1</version>
<type>pom</type>
<include>submodules</include>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2</artifactId>
<version>0.0.1</version>
<type>pom</type>
<include>submodules</include>
</dependency>
</dependencies>
If I remember correctly I was creating a modular project for an ordering system where I had a common api that our internal system would use (REST). I was creating a routing system where I could route an order to a single fulfillment center based on a criteria of the order (country, priority taxes etc). Each of the fulfillment centers had their own api (connectors).
The example is greatly simplified in the original question to make it more the problem more concise. In the real project each connector (1,2,3) would have been a separate pom with multiple dependency jars. One for their client api, then some etl code to match with my original api.
I don't remember how I solved this. I think I just had to include the all the child dependencies.
One way is to create a fourth module which "wraps" the 3 modules as dependencies. This way you could depend on this wrapper module which would.
connectors - packaging: pom
connector1 - packaging: jar
connector2 - packaging: jar
connector3 - packaging: jar
connectorWrapper - packaging: pom (depends on the above three)
Although it would make more sense to explicitly declare a dependency for each connector especially that they are only three.
Alternative solution:
A more dynamic approach (although very much an overkill IMO) is to have this fourth module package the implementation modules in an assembly using a custom assembly descriptor. For example, inside connectorWrapper, you could write an assembly.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>impl-modules</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>pom.xml</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>*:connector*</include>
</includes>
<binaries>
<includeDependencies>false</includeDependencies>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
Note that the descriptor tells the assembly plugin to:
include all modules in the current project reactor, so when you run mvn clean package in the root project, it will include all modules
include only implementation modules (the connector modules), as specified in the include element having *:connector*.
Of course you'll need to configure the assembly plugin to use this descriptor in the connectorWrapper (or whatever other name you choose for this wrapper):
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Then you can run mvn install on the root project to install the assembly artifact, after which you can depend on it from the other project:
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>connectorWrapper</artifactId>
<version>...</version>
<classifier>impl-modules</classifier> <!-- note the classifier -->
</dependency>
</dependencies>
Not entirely sure whether it exactly does what you need but within the latest maven releases you can use the scope import on your dependencies.
The first step would be to create a pom containing all the dependencies you would like to include in other projects:
<project>
<groupId>com.foo</groupId>
<artifactId>connectors</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-api</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-etl</artifactId>
<version>0.0.1</version>
</dependency>
...
</dependencies>
</project>
In the projects you would like to include the connectors you have:
<dependency>
<groupId>com.foo</groupId>
<artifactId>connectors</artifactId>
<version>0.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
See Importing Dependencies for more information.
An alternative approach could be to use the maven assembly plugin and create a single (huge) jar containing all the classes you would like to include (single jar packaging); (for that you also need to create once a pom with all the dependencies and the assembly plugin).
I would write my own maven plugin for this. Judging from your reputation and the question, you could probably have something ready within the hour. Most probably sooner than researching and trying out solutions to do what you want.

Classloader with Maven built jar

I am working on a project which contains a number of subprojects. The structure is something like Project 1, Project 2 and ProjectClassLoader.
Using separate configuration files, I pass in the binary names of the classes from Projects 1 and 2 that need to be loaded each time as arguments to the ProjectClassLoader project.
The ProjectClassLoader gets a handle to the system classloader
ClassLoader loader = ClassLoader.getSystemClassLoader();
which in theory allows it to load any classes which are contained in the classpath.
I'm using Maven to build the projects and handle their associated dependences. Thus each project has it's own individual pom.xml file. The ProjectClassLoader defines a parent pom.xml over Projects 1 and 2 which inherit from this. The parent pom contains dependency entries for both Project 1 and 2.
My understanding was that any dependencies specified in the pom.xml files of these projects would get added to the classpath at runtime. However when trying to load classes using the system classloader, I'm getting class not found execptions.
I have tried using the mvn:exec plugin which I understand includes the dependencies in the classpath when executing jars on the command line but this has not worked.
I'd grately appreciate any help in furthering my understanding of why I can load the classes even though the dependencies are defined in the pom...Thanks in advance
Can you check if your pom matches this configuration a bit?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<properties>
...
<exec.maven.plugin.version>1.2.1</exec.maven.plugin.version>
...
</properties>
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
...
</plugins>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.maven.plugin.version}</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
<classpath />
<argument>com.example.Main</argument><!-- your mainClass -->
</arguments>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
</build>
<dependencies>
...
<dependency>
<groupId>groupId.for.project1</groupId>
<artifactId>project1</artifactId>
</dependency>
<dependency>
<groupId>groupId.for.project2</groupId>
<artifactId>project2</artifactId>
</dependency>
...
</dependencies>
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>groupId.for.project1</groupId>
<artifactId>project1</artifactId>
<version>${project1.version}</version>
</dependency>
<dependency>
<groupId>groupId.for.project2</groupId>
<artifactId>project2</artifactId>
<version>${project2.version}</version>
</dependency>
...
</dependencies>
</dependencyManagement>
...
</project>
Where you fill them with the correct artifacts.
You should then be able to start it with:
mvn exec:exec
Can you post your configuration for your pom plz if it doesn't match, that way it's easier to understand what exactly you currently have in your pom.

Maven: javax.servlet specification deployed

I've a web application configured with Maven which uses a library, also configured with Maven and when I package geronimo-servlet_3.0_spec-1.0.jar is included in WEB-INF/lib and I don't understand why.
I check the library with mvn dependency:tree
$ mvn dependency:tree | grep geronimo
[INFO] +- org.apache.geronimo.specs:geronimo-servlet_3.0_spec:jar:1.0:provided
I check my web app:
$ mvn dependency:tree | grep geronimo
$
However when I run mvn:package the file gets included in WEB-INF/lib.
When I run mvn tomcat:run I can see:
INFO: validateJarFile(/home/stivlo/workspace/private/src/main/webapp/WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Why and how to avoid? Thank you.
UPDATE 1: as requested I add the pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.obliquid</groupId>
<artifactId>test-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>private webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<!-- For Jakarta ORO -->
<repository>
<id>mvnsearch</id>
<name>Maven Search</name>
<url>http://www.mvnsearch.org/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>private</finalName>
</build>
</project>
UPDATE 2: I followed the advice of Stephen C and modified the build section as follows:
<build>
<finalName>private</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war</artifactId>
<version>2.1</version>
<configuration>
<overlays>
<overlay>
<groupId>org.obliquid</groupId>
<artifactId>test-webapp</artifactId>
<excludes>
<exclude>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
However geronimo*.jar still gets included. I guess I've made a mistake in this configuration.
UPDATE 3: Stephen C. says that I should use
the groupId the artifactId of the WAR
file that contains the JAR file(s)
that you are trying to exclude.
I didn't know that WAR files could have a groupId and artifactId, in fact in my pom.xml I don't see any. My project builds a WAR file and has a groupId and an artifactId and those were the ones I tested above without success.
The dependency causing the problem is the following (is a JAR, not a WAR):
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
If I try to use the groupId and artifactId listed in this dependency I've the following error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-war-plugin:2.1.1:war
(default-war) on project test-webapp:
overlay [ id
org.obliquid.helpers:obliquid-helpers]
is not a dependency of the project. ->
[Help 1]
If I try to use the groupId and artifactId of the JAR included by org.obliquid.helpers:
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>)
I have the same error.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-war-plugin:2.1.1:war
(default-war) on project test-webapp:
overlay [ id
org.apache.geronimo.specs:geronimo-servlet_3.0_spec]
is not a dependency of the project. ->
[Help 1]
Reading the War plugin documentation, I found a section about creating skinny WARs. So I tried the following:
<build>
<finalName>private</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
Still without any success, geronimo-servlet_3.0_spec-1.0.jar is still there!
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project test-webapp: overlay [ id org.obliquid.helpers:obliquid-helpers] is not a dependency of the project. -> [Help 1]
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project test-webapp: overlay [ id org.apache.geronimo.specs:geronimo-servlet_3.0_spec] is not a dependency of the project. -> [Help 1]
UPDATE 4: I discovered that the target/private.war file is not a zip of target/private/ directory, but the exclusions are done at packaging time and not by deleting files in target/private/ -- This means, I've to re-test all the things I did before.
Suggestion of gouki: doesn't work, the JAR is still there also in the WAR file.
Suggestion of Stephen C., maybe mis-understood: actually I just noticed that the pom.xml is always invalid whatever groupId/artifactId I put of the three possibilities explained above. So they didn't work for me.
What I found in the documentation (packagingExcludes), works.
Now, if I had to choose one of he answers I would choose Stephen C., because he helped me pointing at the documentation of the WAR plugin (I was reading in the wrong places). However I'd accept an answer that doesn't work, at least in the way I tried (probably wrong). So I'm not going to accept any answer, and add a new answer myself with the final working configuration.
UPDATE 5: I post the relevant part of the pom.xml of obliquid-helpers, that mentions geronimo-servlet_3.0_spec. I've marked it optional and with scope provided, still it gets included by a web-app, unless I mark it as "packagingExclude" in the maven-war-plugin configuration.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<packaging>jar</packaging>
<name>obliquid-helpers</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
[...]
</repositories>
<dependencies>
[...]
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Clearly, something has a dependency on that JAR file. If it is not showing up in the dependency tree, perhaps it is due to a dependency of your webapp WAR file on another WAR file that has this dependency.
If that is the case, then you could get add an <excludes> to the <overlay> element of the build descriptor for the WAR file plugin; e.g.
...
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<overlays>
<overlay>
<groupId>xxx</groupId>
<artifactId>yyy</artifactId>
<excludes>
<exclude>WEB-INF/lib/whatever.jar</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
...
If you are using WAR file overlays, you should always include the clean target in the build. Otherwise you can get old dependencies hanging around in the WAR file. (IIRC, there is a Warning in the Maven output each time you build an overlaid WAR without cleaning!)
In fact, this could be the root cause of your problems. For instance, if previously you had the "geronimo" as an ordinary dependency and you haven't run mvn clean since then, the JAR file could still be hanging around.
Based from your pom.xml, the only dependency that might have dependency on geronimo servlet is
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Can you try excluding the geronimo in this dependency?
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
First I want to thank gouki and Stephen C. for helping me. However their proposed solution didn't work for me. I'm grateful to them, but I can't accept their answer, because it would be misleading since it didn't work for this problem. I've upvoted Stephen C. answer, because he pointed me to the right documentation, which was essential to solve the problem.
Reading the WAR plugin documentation, especially the war:war mojo section, I've found an example on how to create Skinny WARs, which did the trick. So here is below the working configuration, to be added to the build section:
<build>
<finalName>private</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
The archive part is probably not really needed, but I will find out when I deploy the WAR. The part that does the trick is the packagingExcludes tag, that can contain a comma separated list of tokens to exclude from the WAR before packaging.

Categories