Reputation: 3814
I am refactoring a Java application and am trying to move code out of a war file and into a jar file so it can be used across many different web applications. However, one of the requirements is that the developers still need to use breakpoints within the library. To do so I believe I need to package the source with the compiled code. Below is the build lifecycle
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
When I run mvn package
and mvn source:jar package
it creates two jar files, respectively
Then I can attach the source to the dependency.
My question is two-fold
Upvotes: 0
Views: 470
Reputation: 35805
Putting the source code into the JAR is the wrong approach.
You create two JARs (as shown in your question). These JARs go to the repository. Then everyone who uses the JARS will automatically get the -sources
as well. In the usual IDEs, like Eclipse and IntelliJ the -sources
JAR is automatically used for debugging.
Instead of two Maven runs, you should add the source plugin to your POM. Then the -sources
JAR is created during the normal build.
Upvotes: 2