Search code examples
javaeclipsemavenm2eclipse

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.


Solution

  • 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.