See my reply below the quote...

Fri, 22 Mar 2024, /Debraj Manna/:

[...]
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.

The easiest way is probably what Gary Gregory has suggested – extract the common code in its own module.

Your main JAR is likely missing classes as you've applied <includes> configuration globally to the maven-jar-plugin, and not just to the "test-jar" execution:

        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
            <configuration>
              <includes>
                <include>common/**</include>
              </includes>
            </configuration>
          </execution>
        </executions>

You may wish to give the execution a non-default ID, and produce additional JAR with a different classifier:

        <executions>
          <execution>
            <id>common-test-jar</id>
            <goals>
              <goal>test-jar</goal>
            </goals>
            <configuration>
              <classifier>tests-common</classifier>
              <includes>
                <include>common/**</include>
              </includes>
            </configuration>
          </execution>
        </executions>

You'll then use the given classifier when specifying this JAR as a test dependency to other modules.

See also: "How to create an additional attached jar artifact from the project" <https://maven.apache.org/plugins/maven-jar-plugin/examples/attached-jar.html>

--
Stanimir

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to