Gradle downloading dependency into cache instead of maven repository - java

I am trying to maintain the same repository on my filesystem for maven and gradle. But I am running into some problems.
I have the following in my build.gradle file.
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.3.9'
runtime group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.3.9'
runtime 'org.xerial:sqlite-jdbc:3.8.7'
}
GRADLE_HOME is D:\Programming\Java\gradle-2.2.1
GRADLE_USER_HOME is D:\Programming\Java\.m2
My gradle home is the same as my Maven repository.
But when the dependencies are downloaded via gradle they are being downloaded into the GRADLE_USER_HOME\cache instead of the repository folder. What configuration am I missing?
EDIT
I have checked the chapter on dependency management of the book Gradle In Action. Nothing. I have checked the dependency management on gradle's website but it also just says that cache is used.
It seems that there is no such option available in gradle. Can someone confirm?

There is no setting to change that. There is no gradle repository as such. Also, it seems like a bad idea to have gradle use the repository's folder as dependency cache because of the clutter.
If you are trying to publish artifacts built by gradle to said maven repository, you should probably take a look at the maven-publish plugin.
If you are trying to use artifacts from that repository in your build, the way to go would be to add mavenLocal() to your repositories and then just use the compile function in your dependencies.

Yes, I read the source code and just confirmed There is no setting to change that.
Here is my solution:
install a local maven repository manager like Nexus.
config gradle using that repository.

Related

Unable to download Spring Boot 2.1.7.RELEASE

I'm not familiar with Spring eco and to run gradle to install required modules.
I just cloned this spring boot repo and tried to run it
git#github.com:didinj/springboot-mongodb-security.git
Plugin [id: 'org.springframework.boot', version: '2.1.7.RELEASE'] was not found in any of the following sources:
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'org.springframework.boot', version: '2.1.7.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.7.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
at .....
How come? Does this mean the 'org.springframework.boot', version: '2.1.7.RELEASE' is not in this world anymore? If so, the package management system is holly crap.
What should I do? I cloned bunch of git repos from the github and try to run gradle and always have this problem.
Java ecosystem is too broken. Unlike NPM or ruby gem which is so stable and no-brain to use.
Is there related to my gradle setting, java version, or anything else?
Use JDK 8. Change or config MongoDB at https://github.com/didinj/springboot-mongodb-security/blob/master/src/main/resources/application.properties
git clone https://github.com/didinj/springboot-mongodb-security.git
cd springboot-mongodb-security
gradlew bootRun
There is no 2.1.7.RELEASE version of this plugin available at Maven Central Repository (which is used in your build.gradle script), since this version is outdated. But it's still accessible at Gradle Plugin Repository (https://mvnrepository.com/artifact/org.springframework.boot/org.springframework.boot.gradle.plugin/2.1.17.RELEASE).
So you should either use least available plugin version from Central repository (2.2.0.RELEASE) or add Gradle Plugin Repository to the repositories section of your build.gradle
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}

How to include reference to library in java gradle project

I am coming from a C# background. I am used to NuGet and Visual Studio project references so the Java ecosystem has confused me quite a bit.
I have a gradle library project. I want to import org.apache.commons.codec.binary.Base64;
However I keep getting cannot resolve errors.
I am using VSCode as my IDE and I would like to include the codec dependancy. How would I achieve this in VSCode/gradle.
I have downloaded the commons-codec-1.14.jar file, but don't know where to put it in the project.
Gradle is a tool that, among other things, manages your dependencies. This means that, you do not need to manually download and add dependencies to your project. Gradle solves this for you.
See the official documenation on how to handle dependencies with Gradle.
You probably have a build.gradle file, in which you need to include your dependency. It would look something like:
dependencies {
implementation 'commons-codec:commons-codec:1.14'
}
This lets Gradle know that you have a dependency to version 1.14 of commons-codec which your codes need to build and run.
This will automatically be downloaded from a remote repository, which you also can specify in your build.gradle file:
repositories {
mavenCentral()
}
This tells gradle to download the dependencies from Maven Central, which probably is the most typical Maven/Gradle repository and most likely hosts most dependencies you would need.

Gradle dependencies for Jupyter notebook

I'm writing Java code in a Jupyter Notebook via IJava . I want to add external dependencies such as OpenCSV. Using gradle, this would normally be incorporated in the build.gradle file via the line
compile 'com.opencsv:opencsv:4.3.2'
How can I add dependencies at runtime via gradle in the Jupyter notebook?
There is the maven magic for this. Since the dependency is on maven central, it is as easy as adding %maven com.opencsv:opencsv:4.3.2 in a cell.
For example
%maven com.opencsv:opencsv:4.3.2
import com.opencsv.CSVReader;
// ...
The name maven is slightly misleading as Maven (or Gradle) is a build tool rather than strictly a dependency manager, but as the dependencies are often resolved from the Maven Central repository the notion of adding a "maven dependency" was a good enough metaphor.

mockito in gradle not working for java project

I have a basic java project and I want to run tests using Mockito (since I use it at work and it's easy). So I referred to this link and added the following to my build.gradle
dependencies {
testCompile 'junit:junit:4.11'
testCompile "org.mockito:mockito-core:1.+"
}
Even though I think mavenCentral() should be enough, I went ahead and added these to my repositories list
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
The ./gradlew clean build runs perfectly fine, but when I try to add the import for Mockito it doesn't get it. And my External Libraries folder in the project doesn't have the Mockito jar. I even tried using mavenLocal() in the hope that it'll pick it up from my local .m2 directory, but it doesn't. I've been looking around and trying out all combinations for 2 hours now with absolutely no result. I don't want to add the jar to the project. I want to let gradle pull it from the central repo and compile it.
Thanks for any help in advance.
I found the answer here Apparently clicking on that refresh button refreshes the dependencies. Else right click on module -> Open Module settings -> Go to Dependencies tab and add your dependency either from your local m2 folder or provide the maven central URL for the dependency.
I was too used to Eclipse doing stuff for me I guess. :)
Is this in Eclipse? If so, right-click on the project and go gradle > Update All (I think it is - I don't have open at moment and don't think about it any more). This will update the dependencies.
If you are referring those libraries other than test package, that is main package you will get this error.
Because you provided scope testCompile in build.gradle, so these libraries are available only in test package.
So, change testCompile to compile in build.gradle.

grails dependency resolution

My Grails project depends on an intenal library Commons.jar which is built with Maven. In BuildConfig.groovy I have configured it to look for this dependency first in the local Maven repository, then in the company-wide repository.
repositories {
// Read the location of the local Maven repository from $M2_REPO
mavenLocal System.getenv("M2_REPO")
mavenRepo "http://build.mycompany.com/wtp_repository"
}
plugins {
build 'org.grails.plugins:spring-security-core:1.0.1'
}
dependencies {
compile ('com.mycompany:Commons:1.0.0-SNAPSHOT')
}
When I build Common/jar (using mvn deploy), it is stored first in mavenLocal, then copied to mavenRepo. However, when I build the Grails app, it looks for the JAR in the following locations:
Ivy cache (defaults to ~/.ivy2/cache)
mavenLocal (defined by $M2_REPO)
mavenRepo (http://build.mycompany.com/wtp_repository)
So the Grails app is constantly picking up an old version of the JAR from the Ivy cache, which is never updated when the Commons project is built.
I guess I could fix this problem if I knew how to:
Prevent Grails for looking for dependencies in the Ivy cache (though I guess disabling the cache might slow down my builds considerably)
Ensure that the Ivy cache is also updated when I build Commons
However, it seems that anyone else that references SNAPSHOT artifacts of Maven projects should also have this problem, so perhaps I'm missing something?
Thanks!
I guess this discussion is related to the problem you have and possibly suggests some workaround/solution.

Categories

Resources