1

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.

Alessandro C
  • 3,310
  • 9
  • 46
  • 82
  • here is a corresponding report against the STS issue tracker: https://issuetracker.springsource.com/browse/STS-4430, however I think this is an issue with the general Maven Integration for Eclipse (m2e) and therefore a report against the m2e project makes more sense (see my comment on the issue). – Martin Lippert Feb 09 '17 at 09:46
  • Ok, thank you very much Martin, I'll report the bug to the m2e project. – Alessandro C Feb 09 '17 at 14:12
  • I also ran into this issue, would you happen to have any updates to pass on please? – asenec4 Aug 27 '21 at 13:15

0 Answers0