Can't add source code to jar file in Maven Dependency
I have a maven project that uses jar files of another project B in version 1.0 of my team. version 1.0 of project B has been pushed to the local Maven repository.
The problem is that project B does not include source code. So in project A, right click on JAR B in Maven Dependencies in Package Explorer , select Java Source Attachment and set the path location in project B (in version 1.1 , I no longer have the source of the previous version) the source folder ( xxx/projectB/src/main/java/
). But Maven doesn't seem to find any source class.
source to share
Several ways to solve this problem:
- Have team B use the Maven release plugin. The release plugin will by default download the sources and javadoc artifacts when a version is released.
- Download the original B artifact yourself. Since you seem to be locally, upload it to the Maven repository. Then you can get it.
- Install them to your local repository (on your local machine) using the Maven Install Plugin . The documentation even shows an example of how to do this for the sources artifact. The downside is that it will only be available to you, no one else.
Since you are using m2eclipse, you can right click on the project and then select Maven> Download Sources.
source to share
Add to your B pom (I think one of these should work):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</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>
</build>
source to share