4
votes

We are using a third party library that doesn't exist in Maven Central Repository and we wan't to deploy this archive as an artifact to Artifactory. We are trying to do that via Artifactory UI and we successfully deployed both archive.jar and archive-sources.jar. The problem occurs when we add this dependency through Gradle to our build.gradle script. Archive.jar is fetched from our repository but archive-sources.jar is not fetched. We are developing with Eclipse and you can see the problem through screenshot.

enter image description here

We tried several things including defining classifier in Artifactory UI, editing pom with Artifactory POM Editor, publishing pom file manually and nothing worked. Whatever we do we couldn't get the source of this archive. Any kind of help would save a lot of time and effort. Thanks!

Screenshot of Artifactory UI:

enter image description here

2
How the sources jar looks like in Artifactory? Can you paste the screenshot of a tree (or simple) browser? - JBaruch
Did you check for gradle requests for the sources jar in the Artifactory request log? - Dror Bereznitsky
@JBaruch I have added the screenshot. More files I can provide if you need them. - leventunver
@drorb We can't see any request of sources in artifactory's request.log. One strange thing is we had 2 libraries like this. The one that we worked on yesterday started to download sources today. But the other library does not work still. We don't have any logical explanation for this strange behaviour. We defined <sourceDirectory> in .pom file and added pom.xml and properties in META-INF of archive manually. One of the jars started to work by this way, but the other one didn't. - leventunver
Does Gradle try to download the source files? You can use gradle --info --refresh-dependencies eclipse for getting more information and trying to re-download all dependencies. - Andreas Schmid

2 Answers

1
votes

We have solved the issue but it was a little bit complicated. There are many steps to apply the solution:

In the case of jain-sdp archive, here are the steps:

1- Deploy jain-sdp sources artifact with classifier "sources" as it is shown in the screenshot.

2- Manually upload jain-sdp.pom file with including the "sourceDirectory" tag:

  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>javax.sip</groupId>
    <version>1.2</version>
    <artifactId>jain-sip</artifactId>
  </parent>
  <groupId>javax.sdp</groupId>
  <artifactId>jain-sdp</artifactId>
  <version>1.0.1111</version>
  <packaging>jar</packaging>
  <name>jain-sdp</name>
  <url>http://jain-sip.dev.java.net</url>
   <build>
    <sourceDirectory>../../src/javax/</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <includes>
                    <include>**/sdp/**</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>target/javax/</directory>
            <includes>
                <include>sdp/**</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>    
   </build>

</project>

3- Manually create the below files.

pom.xml:

  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>javax.sip</groupId>
    <version>1.2</version>
    <artifactId>jain-sip</artifactId>
  </parent>
  <groupId>javax.sdp</groupId>
  <artifactId>jain-sdp</artifactId>
  <version>1.0.1111</version>
  <packaging>jar</packaging>
  <name>jain-sdp</name>
  <url>http://jain-sip.dev.java.net</url>
   <build>
    <sourceDirectory>../../src/javax/</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <includes>
                    <include>**/sdp/**</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>target/javax/</directory>
            <includes>
                <include>sdp/**</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>    
   </build>

</project>

pom.properties:

#Generated by Maven
#Tue Feb 05 21:33:14 CET 2008
version=1.2
groupId=javax.sdp
artifactId=jain-sdp

4- Include the files that have been created in Step 3 to the below path in the archive:

META-INF/maven/javax.sdp/jain-sdp/pom.properties META-INF/maven/javax.sdp/jain-sdp/pom.xml

Note that these files should be added to jain-sdp.jar, not jain-sdp-sources.jar

5- Upload jain-sdp.jar to the Artifactory through UI

I think that these steps should be done manually. There is no other way to solve this problem that I can think of. sourceDirectories should be included manually to pom files and archives manually.

0
votes

Add your Source files into your jar, observing the same directory structure as for the class file contents.

This means you don't need to manage another artifact and don't need to update your pom.xml

Simplest steps to perform this addition is on the CLI: change into your source directory and "update" the jar. Doing it with this specific current working directory which will preserve the correct relative filenames.

For example, I have directory structure:

~/project/src/com/mycompany
~/project/target

and have built a jar into ~/project/target named existing.jar

$ cd ~/project/src; jar uvf ../target/existing.jar com

$ jar tvf ~/project/target/existing.jar

should show class files and source files in the same tree.

  ...
  6923 Sun Sep 18 23:19:36 PDT 2016 org/spacehq/reddit/util/http/ResponseType.class
  4676 Sun Sep 18 22:30:38 PDT 2016 org/spacehq/reddit/util/http/ResponseType.groovy
  ...

IntelliJ IDEA detects these source files in the jar and presents them when opening the related class file. I'd assume other full featured IDEs would also.

You should of course be able to automate this somehow with Maven, to take out the human step, but this is good for a one-off.