0

I'm trying to download the source code from a .jar file. I know about mvn dependency:sources but I don't have access to the jar's pom.xml file to run that command.

What I am trying to accomplish: I have two separate projects (Project_1 and Project_2). Project_1 has a dependency on Project_2 in which a version of Project_2 is downloaded from Nexus. I am adding

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

into the Project_2 pom file. How then will I be able to download the source jar file to Project_1 if all I have is the dependency to Project_2? I have no access from Project_1 to the Project_2 pom to run the command.

  • is the sources jar available in Nexus as well? When project2 is deployed on Nexus, is also its sources jar deployed? – A_Di-Matteo Apr 26 '16 at 20:50
  • 1
    @A.DiMatteo When Project_2 goes through a build, it's my understanding that Nexus it will be available in Nexus automatically – ilovecats06 Apr 26 '16 at 21:04
  • not necessarely, the deploy phase will not attach the sources jar automatically, unless the pom file will specify so. Browsing your Nexus repository, do you see the sources jar under the project2 directory where you actually also see the final jar? – A_Di-Matteo Apr 26 '16 at 21:05
  • Side-note, the sources JAR, if present, should have a name like `...-sources.jar`. If this artifact was released with the `maven-release-plugin`, it should have created a sources JAR. But the fact that you do not have the POM is concerning. How did you obtain that JAR in the first place? – Tunaki Apr 26 '16 at 21:20
  • @A.DiMatteo No because I have not deployed yet. Would you be able to answer both scenarios? 1) The source jar shows up in Nexus 2) The source jar does not show up in Nexus – ilovecats06 Apr 26 '16 at 21:21
  • @Tunaki I do see the sources jar locally when I build Project_2. I want to know if when I do a release build that this source jar will appear in Nexus. And if/when it does, how will Project_1 obtain the source jar – ilovecats06 Apr 26 '16 at 21:24
  • If you have the sources JAR locally, why not install it directly by hand on the Nexus server? – Tunaki Apr 26 '16 at 21:25
  • @Tunaki Because this cource jar needs to be used by other people too. And constant deployments of Project_2 would require this by hand everytime. I would like it generate during deployment and then would like to know how others can get to it – ilovecats06 Apr 26 '16 at 21:37
  • Why? If you have a dependency on project2, it is a fixed version dependency so you just need to upload the source for that specific version. Or am I misunderstanding something? – Tunaki Apr 26 '16 at 21:38
  • @Tunaki The version of Project_2 will be changes constantly. So with each new version, it would require a new source upload – ilovecats06 Apr 26 '16 at 21:41
  • But you said *Project_1 has a dependency on Project_2 in which a version of Project_2 is downloaded from Nexus*. You're talking about a dependency in a specific version. Why would project2 in this version, change? – Tunaki Apr 26 '16 at 21:42
  • @Tunaki Project_2 is constantly being changed and deployed...so new versions of it are always being produced. People using Project_1 will need to be able to see up-to-date source code from what is in Project_2. My question again: How, from Project_1, will I be able to get the source code from Project_2 – ilovecats06 Apr 26 '16 at 21:45
  • Well either the source code is published along with the artifact or it is not. It seems that the source code isn't published but you have it locally? I don't understand. – Tunaki Apr 26 '16 at 21:46
  • @Tunaki It is published to Nexus. But if Project_1 has the Project_2 dependency in the pom, will the sources jar just appear as well? Or will something else need to be done? – ilovecats06 Apr 26 '16 at 21:52
  • Ha well if the sources are deployed along with the JAR then there is nothing you have to do. Your IDE will download the sources automatically (if configured like it). But I still don't understand the part where you said you didn't have the POM. The POM should be deployed along with everything else also. – Tunaki Apr 26 '16 at 21:53
  • @Tunaki From project_1, I see the project_2 dependency jar file, and can open it where I see the packages and pom within. What I meant is that through command line, I cannot navigate to that pom file to run the mvn dependency:sources. I can right click on the jar and click Maven -> Download Sources but that doesn't seem to do anything – ilovecats06 Apr 26 '16 at 22:30

0 Answers0