Can we change .gradle path from Users location to project location in springboot? - spring-boot

Since I want to build project in Azure DSVM where there is not internet connectivity.
And I wanted to take all gradle dependencies to that machine. And build + run on the DSVM machine.
My project structure as follows
I wanted my spring gradle to download all dependencies into .gradle/ directory inside my project.
And link to this location only. So, that I can apply same settings into my target DSVM machine.
I dont have option to download jars from internet inside my DSVM, but I can copy those manually that is possible for me.
What settings I need to apply ?

I have fixed above issue by adding gradle.properties file inside USER_HOME/.gradle/
directory with following values :-
systemProp.http.proxyHost=<IP-Address>
systemProp.http.proxyPort=<Port>
systemProp.https.proxyHost=<IP-Address>
systemProp.https.proxyPort=<Port>
The IP Address & Port number should shared by respective Firewall network.

Related

Moving gradle build to another machine

It seems that when Gradle 3.1 downloads the dependencies for your project it stores them in:
C:\Users\username\.gradle\caches
I tried copying the contents of this folder to a different machine that has a fresh Gradle 3.1 installation, but when I try to build my project it still tries to download all of the dependencies from scratch, which then fails because the new machine has no internet connection.
How do I get around this?
Compress main folder C:\Users\username.gradle to gradleHome.zip
Copy and uncompress this gradleHome.zip file to another folder for example D:\gradle_home
set gradle_home environment variable to this new folder. See how to change environment variables in windows here.enter link description here

Downloaded path for Gradle comple statement [duplicate]

How does Gradle store downloaded jar files on the local file system? Maven stores them in the .m2 directory under USER_HOME, but where does Gradle store them? I checked the .gradle folder there, but saw only compiled scripts.
On Mac, Linux and Windows i.e. on all 3 of the major platforms, Gradle stores dependencies at:
~/.gradle/caches/modules-2/files-2.1
Gradle caches artifacts in USER_HOME/.gradle folder. The compiled scripts are usually in the .gradle folder in your project folder.
If you can't find the cache, maybe it's because you have not cached any artifacts yet. You can always see where Gradle has cached artifacts with a simple script:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:12.0'
}
task showMeCache doLast() {
configurations.compileClasspath.each { println it }
}
Now if you run gradle showMeCache it should download the dependencies into the cache and print the full path.
In Windows 10 PC, it is saved at:
C:\Users\%USERNAME%\.gradle\caches\modules-2\files-2.1\
Gradle's local repository folder is:
$USER_HOME/.gradle/caches/modules-2/files-2.1
Defined dependencies will be loaded from remote repositories into gradle's local repository folder. For each loaded file, gradle will be create a new folder named with md5 value of the original file (pom,jar,..). Full path for the dependency file is made up from :
groupid + artifactid + version + FILE_MD5_VALUE + FILE_NAME
If our defined dependency is:
compile 'org.springframework:spring-jdbc:4.3.4.RELEASE'
Then the library will be loaded into :
/$USER_HOME/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/4.3.4.RELEASE/42175d194cf6aa7c716c0887f30255e5c0a5262c/spring-jdbc-4.3.4.RELEASE.jar
In fact the cache location depends on the GRADLE_USER_HOME environment variable value.
By default, it is $USER_HOME/.gradle on Unix-OS based and %userprofile%.\gradle on Windows.
But if you set this variable, the cache directory would be located from this path.
And whatever the case, you should dig into caches\modules-2\files-2.1 to find the dependencies.
If you want your dependency files to be in some specific folder you can simply use a copy task for it. For Eg.
task copyDepJars(type: Copy) {
from configurations.compile
into 'C:\\Users\\athakur\\Desktop\\lib'
}
I am on windows,
You should be able find the dependencies inside
$USER_HOME.gradle\caches\artifacts-24\filestore
Many answers are correct!
I want to add that you can easily find your download location with
gradle --info build
like described in https://stackoverflow.com/a/54000767/4471199.
New downloaded artifacts will be shown in stdout:
Downloading https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-parent/2.1.7.RELEASE/spring-boot-parent-2.1.7.RELEASE.pom to /tmp/gradle_download551283009937119777bin
In this case, I used the docker image gradle:5.6.2-jdk12.
As you can see, the docker container uses /tmp as download location.
You can use the gradle argument --project-cache-dir "/Users/whatever/.gradle/" to force the gradle cache directory.
In this way you can be darn sure you know what directory is being used (as well as create different caches for different projects)
I just stumbled onto this while searching for this answer. If you are using intellij, you can navigate to the file location, but opening the external lib folder in the project explorer, right clicking on the jar, and select Open Library Settings.
It took me a while to realize this, hence the additional answer. Hopefully it can save folks time. Note that if you are running sudo gradle the dependencies may not be in your home directory, even if sudo echo $HOME returns /Users/<my-non-root-user>/. On my Mac, Gradle was caching the dependencies in /private/var/root/.gradle/caches/.
In case it is an Android gradle project - you can find the android libraries below your $ANDROID_HOME/extras/android/m2repository folder
In android studio do the following steps to check the gradle downloaded jar file.
Set project structure view to "Project"
At bottom External library section available, expand it.
Here you can see downloaded jar files.
On my windows machine with "Buildship 2.0.2" plugin installed in eclipse, dependencies are stored :
$USER_HOME.gradle\caches\modules-2\files-2.1
For my case, I was using an Ivy repository, and my Gradle dependencies were stored in ~/.ivy2/.

Maven dependency generation

Is there a plugin available for maven which i can use to generate all the dependencies of a project ? For example I have a server folder which contains folders like below
-server
--test1
--test2
--test3
when i run a particular comand from server folder it should generate all the dependency info in the target folder of server. I know if I use dependency:analyze-report it will generate in all the folders target, but I want then all together in the top folder. Please let me know if there is any way.

Errors when import existent maven project into eclipse kepler

I have imported a existent maven project (swagger for jersey jax-rs) into eclipse.
I get a bunch of errors:
It always has to do with the jackson-databind.jar
Example error:
Archive for required library: '.../.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.5/jackson-databind-2.1.5.jar' in project 'swagger-core_2.9.1' cannot be read or is not a valid ZIP file
I cannot find the .m2 folder? I am new to the maven stuff,
do i have to install something extra before i import a maven project into eclipse?
Thx
I cannot find the .m2 folder?
By default the .m2 directory is located at the home directory.
For *Unix operating systems, it will be something like /home/<user_who_fires_maven_commands>/.m2/...
For Windows machines , the m2 will be located at C:\Users\<user>\.m2\...
As for the exception you are getting
Archive for required library: '.../.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.1.5/jackson-databind-2.1.5.jar' in project 'swagger-core_2.9.1' cannot be read or is not a valid ZIP file
It is most probable that the archive file has gotten curropted ( maybe a download issue or might be possible that its sha1 doesn't match with the one that is on the central repo ). So you can try by simply deleting this jar file and then run mvn install and it will re-attempt to download the file again.
Another thing I would like to point out is that since this is a new eclipse installation, I would suggest that you re-index your local m2 folder so that this new eclipse knows about the files and folders inside the original m2 folder. To re-index, goto Window -> preferences --> Maven --> User settings --> there will be a text field stating the path of the .m2 ( make sure its correct ) and then press re-index

Managing external JARs build paths in git controlled eclipse project created in Ubuntu and cloned in Windows

I am having an eclipse project created on Ubuntu, in which all the JARs that I am using, are located in a folder /home/xyz/AllJARs. Here the /home is the system home folder. The project as well as the AllJARs folder is git version controlled on a central git server.
So, all the paths to these JARs in the project's build path are /home/xyz/AllJARs. When I'm cloning the project repo and the AllJARs repo on a Windows machine, I'm shown errors related to build path since it can't find the path /home/xyz/AllJARs.
How can I manage this situation where I can have external JAR files in build paths which can work on Ubuntu as well as on a Windows machine? Thanks in advance.
You have two easy options:
use relative paths: for example, put the JAR folder in the folder above your project, then you can set the JARs' paths to ../AllJARs/
put JARs into project: you can also just put the JARs into the project folder; if you've set them up as "External JARs" in project settings, you'll have to remove them from that list, and re-add them with "Add JARs". Eclipse will then look for them locally in the project folder. If you don't want to commit the JARs to the git repo (size and/or permission being a problem), you can just copy them into the Project folder after cloning. While they're not there, you'll be shown a warning, but once Eclipse can find them, everything's fine.

Resources