I think the "simple" solution is to use 2 maven modules, then you don't
need to do anything special. The layout does not make sense to me so I must
be missing something. If the common code is needed for both main and test,
then it should be in main. You can put that common code in its own package
to signal its specific purpose.

Gary


On Fri, Mar 22, 2024, 3:29 AM Debraj Manna <subharaj.ma...@gmail.com> wrote:

> I have a Maven module named synapse.
>
> main
>   java
>     package1
>       A.java
>
> test
>   java
>     common
>       C.java
>     package1
>       ATest.java
>
> Can someone let me know if in Maven I can create a non-executable jar
> containing all non-test code (main/) and another test-jar containing only
> the code under the package test/java/common?
>
> I tried the below
>
> <build>
>   <plugins>
>        <plugin>
>         <groupId>org.springframework.boot</groupId>
>         <artifactId>spring-boot-maven-plugin</artifactId>
>         <configuration>
>           <skip>true</skip>
>         </configuration>
>        </plugin>
>        <plugin>
>          <groupId>org.apache.maven.plugins</groupId>
>          <artifactId>maven-jar-plugin</artifactId>
>          <version>3.3.0</version>
>          <configuration>
>           <includes>
>             <include>common/**</include>
>           </includes>
>         </configuration>
>         <executions>
>           <execution>
>             <goals>
>               <goal>test-jar</goal>
>             </goals>
>           </execution>
>         </executions>
>       </plugin>
>      </plugin>
>   </plugins></build>
>
> I am observing that the test-jar is getting created as expected containing
> only the code from test/java/common but the non-executable, non-test jar
> does not contain the code from main/java/package1.
>
>    - Maven Version - 3.8.4
>    - Java 17
>

Reply via email to