I know this is not recommended practice and I have read:
http://www.sonatype.com/people/2010/01/how-to-create-two-jars-from-one-project-and-why-you-shouldnt/
which I agree upon. But currently I need to solve the following issue:
I have a project with multiple src folders A and B (using the build-helper-maven-plugin). I need to create two corresponding jars A (the default jar) and B. Jar A contains the classes from src folder A and jar B contains the classes from src folder B.
First I create the default jar A and try to exclude all classes from src folder B:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>**/B*</exclude>
</excludes>
</configuration>
</execution>
But when I inspect the A jar it contains classes from packages in source folder B. Is my reqex exclude notation wrong/does it only work on packages?
Based on the below answers I now do:
<properties>
<artifactId.model>${project.artifactId}-model-${project.version}</artifactId.model>
<artifactId.default>${project.artifactId}-${project.version}</artifactId.default>
</properties>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>make-model-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${artifactId.model}</finalName>
<descriptors>
<descriptor>src/main/assembly/model.xml</descriptor>
</descriptors>
<attach>true</attach>
</configuration>
</execution>
<execution>
<id>make-default-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${artifactId.default}</finalName>
<descriptors>
<descriptor>src/main/assembly/default.xml</descriptor>
</descriptors>
<attach>true</attach>
</configuration>
</execution>
</executions>
</plugin>
where the descriptor for the model is:
<assembly>
<id>model</id>
<formats>
<format>jar</format>
</formats>
<baseDirectory>target</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/model_a</directory>
<includes>
<include>**/**</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/model_b</directory>
<includes>
<include>**/**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
I then attach the jars using the build-helper. THe problem with the above is obviously that I get the .java files and not the compiled .class files. Since all .class files are located in the same target/classes folder for all source folders (see noahz comment) I need to manually specify each include/exclude for the relevant packages - so this approach is a no go :-( I think the best approach is to create a sub-project.