Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

gradle

jar

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?

like image 682
Alex Avatar asked Dec 07 '17 00:12

Alex


2 Answers

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.

like image 91
ddarellis Avatar answered Sep 28 '22 04:09

ddarellis


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.

like image 20
Danio Avatar answered Sep 28 '22 02:09

Danio