Installing 3rd party JAR's

If I put a JAR on github for download, can I then use github itself as a repo which Gradle will pick up? Just me using my own JAR’s.

see also:

http://kwebble.com/blog/2014/02/19/use-github-to-host-your-own-maven-repo

http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

I use github as a poor man’s maven repository here. See the readme which states that maven/gradle must use the “raw” url. Eg:

https://raw.github.com/<user>/<project>/master

I can use any project (which builds a library JAR) with this approach? Please elaborate on how to use this. You’re just showing an example where you do this?

apply plugin: 'java' 
repositories {
   maven {
      url "https://raw.github.com/uklance/releases/master" 
   } 
} 
dependencies {
   testCompile "org.tader:tader-core:0.0.1"
}

Here’s the build for the library:

`
thufir@mordor:~/java/hello_api$
thufir@mordor:~/java/hello_api$ gradle clean build
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test

net.bounceme.mordor.hello.TestJunit > testPrintMessage STANDARD_OUT
Hello World

net.bounceme.mordor.hello.TestJunit > testPrintMessage PASSED
:check
:build

BUILD SUCCESSFUL

Total time: 5.927 secs
thufir@mordor:~/java/hello_api$
thufir@mordor:~/java/hello_api$ jar -tf build/libs/hello_api-0.0.1.jar
META-INF/
META-INF/MANIFEST.MF
net/
net/bounceme/
net/bounceme/mordor/
net/bounceme/mordor/hello/
net/bounceme/mordor/hello/HelloLibrary.class
thufir@mordor:~/java/hello_api$
`

The client of this hello world library fails to build:

`
thufir@mordor:~/java/hello_gradle$
thufir@mordor:~/java/hello_gradle$ gradle clean build
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not resolve all dependencies for configuration ‘:testCompile’.

Could not find net.bounceme.mordor:hello_api:0.0.1.
Searched in the following locations:

https://repo1.maven.org/maven2/net/bounceme/mordor/hello_api/0.0.1/hello_api-0.0.1.pom

https://repo1.maven.org/maven2/net/bounceme/mordor/hello_api/0.0.1/hello_api-0.0.1.jar

https://raw.github.com/thufir/hello_api/master/net/bounceme/mordor/hello_api/0.0.1/hello_api-0.0.1.pom

https://raw.github.com/thufir/hello_api/master/net/bounceme/mordor/hello_api/0.0.1/hello_api-0.0.1.jar
Required by:
:hello_gradle:unspecified

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or
    –debug option to get more log output.

BUILD FAILED

Total time: 22.745 secs
thufir@mordor:~/java/hello_gradle$
`

I see that there are binaries at:

which seems odd, because it’s not standard to include binaries in a repo,
is it?

I tried to upload my JAR to releases, but they only support ZIP – JAR
files are ZIP files, so, not sure what to make of that.

How do I upload my JAR file, hello_api, on to releases? Or, do I need to
make a “releases” repo on github and just add the JAR?

I asked on one of the stackoverflow websites:

I see that there are binaries at:
https://github.com/uklance/releases/tree/master/org/lazan/tapestry-offline/0.0.1
which seems odd, because it’s not standard to include binaries in a repo, is it?

I’m confused, aren’t you specifically asking how to use github as a repository for your jars? I’m showing you how (and yes this is not what I’d call ‘standard’)

How do I upload my JAR file, hello_api, on to releases? Or, do I need to make a “releases” repo on github and just add the JAR?

Yes, that’s what I’ve done. I add jars via git commit and git push

I see.

Ok, I’ll create a releases repo and upload the JAR. I was hoping that I
was overlooking some way of using github “releases” feature…

Ah, I finally understand what you want

You could do something like:

dependencies {
   compile fileTree("$buildDir/unzipped") 
} 

ext.downloads = [
   [zip: "http:/github.com/xxx/archives/foo.zip", jar: "someJar.jar"], 
   [zip: "http:/github.com/yyy/archives/bar.zip", jar: "anotherJar.jar"]
]
task downloadAndUnzip {
   // setting this input property allows  up to date checking 
   inputs.property "downloads", downloads
   outputs.dir "$buildDir/unzipped"
   doLast {
      delete fileTree("$buildDir/unzipped") 
      downloads.each {
         // download $it.zip to a temp dir
         // extract $it.jar to $buildDir/unzipped
      } 
   } 
} 
compileJava.dependsOn downloadAndUnzip

Thanks. I think I got it. What I don’t understand is why you have a “releases” repo. It seems that it is possible to upload JAR files to github through the “releases” tab.

Did this feature recently changed? I would swear that I tried to upload JAR files and was denied by github…

I initially wanted to host my jars on maven central but found the barrier to entry to high (lots of pom.xml requirements) so I figured out how to host a maven repository on github. I’ve since started hosting one library on bintray and plan to host the rest on bintray when I get the time.

I’m not convinced that the github releases tab can be used as a maven repository. Keep in mind that there’s not only your classes jar that requires hosting, there’s a pom file and also optional javadoc and sources jars too. It’s also likely you’d want more than one library per repository which doesn’t really align with the releases for a single project. Otherwise users of your libraries would need to configure a repository for each library.

for what it’s worth, I went in another direction: jitpack. It seems ok, 90% there:

Thank you for the help. My computer died in the middle of your helping me, so it dragged out a bit.

Lance,

I took about 99 false paths, of course it was not complex at all, in retrospect.

It’s quite simple, using JitPack. Sample hello world here:

which pulls in another repo. No need to upload JAR’s at all! :slight_smile:

Interesting… I see jitpack is automatically building your github repo and publishing your artifacts


https://jitpack.io/com/github/THUFIR/hello_api/master-SNAPSHOT/index.html

And my maven built jar is here (not a single line of config required!)