Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't attach add source code to a jar file in Maven Dependency

I have a maven project A which uses jar files of another project B at version 1.0 of my team. The version 1.0 of project B has been submitted to the local Maven repository.

The problem is that project B does not include source code. So in project A, I right-click on the JAR B under Maven Dependencies in the Package Explorer, select Java Source Attachment and setup the Location path at project B (at version 1.1, I don't have the previous version source anymore) source folder (xxx/projectB/src/main/java/). But it seems like Maven doesn't find any source class.

like image 970
bnguyen82 Avatar asked Nov 20 '25 09:11

bnguyen82


2 Answers

A couple ways to solve this:

  1. Ask the B team to use the Maven release plugin. The release plugin will by default upload sources and javadoc artifacts when you release a version.
  2. Upload the B sources artifact yourself. Since you seem to have it locally, upload it to your Maven repository. Then you should be able to retrieve it.
  3. Install them in your local repository (on your local machine) using the Maven Install Plugin. The documentation even shows an example on how to do that for a sources artifact. Downside is that it will only be visible to you, nobody else.

Since you're using m2eclipse, you can then right-click on the project, then select Maven > Download Sources.

like image 66
nwinkler Avatar answered Nov 21 '25 22:11

nwinkler


Add to your B pom (I think one of them 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>
like image 40
Andrzej Jozwik Avatar answered Nov 21 '25 23:11

Andrzej Jozwik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!