I have a Maven Project in Spring Tool Suite, with this simple structure:
[parent_project]
pom.xml
[Module1]
pom.xml
[Module2]
pom.xml
I want to make a double version of the Module1 project, so I used the classifier
tag in the pom.xml
of Module1 project, using this plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>test</classifier>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<excludes>**/test/module1/excluded/**</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The Module2 has this dependency
of the Module1 in its own pom.xml:
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>Module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>test</classifier>
</dependency>
</dependencies>
I have written a simple JUnit test case in the Module2:
public class UseModuleTest {
@Test
public void test() {
Module1Class module1Class = new Module1Class();
ToBeExcluded toBeExcluded = new ToBeExcluded();
}
}
If I make a mvn:install
of the Module1 project, it creates correctly two jars:
Module1-0.0.1-SNAPSHOT.jar
Module1-0.0.1-SNAPSHOT-test.jar
But the strange thing happens when I run the JUnit test.
If I mantain the Module1 project opened, the test fails on the first row, with the error:
java.lang.NoClassDefFoundError: test/module1/Module1Class
at test.UseModuleTest.test(UseModuleTest.java:14)
...
Caused by: java.lang.ClassNotFoundException: test.module1.Module1Class
...
If I close the Module1 project, the test fails at the second row, as expected (by the fact that the "-test.jar" excludes every class in the "excludes" package).
The question is: how can I use the classifier without closing the project in STS? It seems that if I use the <classifier>
tag, the dependencies are not resolved correctly by the IDE.
Thanks in advance.