Friday, December 15, 2017

How to install a compiled by Gradle jar into the local Gradle Repository files-2.1 instead of the Maven repository?

Leave a Comment

In my build.gradle, I added the plugin:

apply plugin: 'maven' 

Then using “gradle install” I can copy the resulted jar into the maven repository : ~/.m2/repository

However, my Gradle repository resides in ~/.gradle/caches/modules-2/files-2.1. How can I install the jar into this repository?

4 Answers

Answers 1

mavenLocal() is resolved like this:

In order to make use of a non-standard local maven repository, you can use the following configuration in your build.gradle:

repositories { maven { url '/Users/manuelj/apache/maven/repository' } }

Answers 2

A build.gradle sample to create a Jar file along with its logback dependencies. using mavenlocale() apply plugin: 'java'

apply plugin: 'eclipse'

version = '1.0'

sourceCompatibility = 1.7

target Compatibility = 1.7

//create a single Jar with all dependencies

task fatJar(type: Jar) {

 manifest {      attributes 'Implementation-Title': 'Gradle Jar File Example',          'Implementation-Version': version,          'Main-Class': 'com.mkyong.DateUtils' } baseName = project.name + '-all'  from { configurations.compile.collect { it.isDirectory() ? it :  

zipTree(it)

}

} with jar }

//Get dependencies from Maven central repository

repositories {

mavenCentral() 

}

//Project dependencies

dependencies {

compile 'ch.qos.logback:logback-classic:1.1.2' 

}

Reference create a Jar file along with its logback dependencies.

Answers 3

If you insist on manipulating the cache, then your best bet is to write a shell script that will manually replace latest JAR in the cache.

The reason is that Gradle does not come with this functionality built-in, as Gradle uses notion of "local cache" in a strict sense, as opposed to "local repository" which is used by Maven.

The difference is that you are never supposed to save files to local cache manually.

To solve your problem the recommended way: Suppose that project A is a dependency of project B. Then you can call publishToMavenLocal command in project A to refresh the depedency. Add mavenLocal() repository in gradle.build of project B, so every time you build project B, Gradle will check the local repository when resolving the dependency A.

Answers 4

What worked for me is gradle install -Dmaven.repo.local=the/path/of/the/folder.

I don't know which IDE you are using but in eclipse you can add a new Run Configuration, in Gradle taks add install and in program arguments -Dmaven.repo.local=the/path/of/the/folder.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment