Build and run gradle project on another machine - gradle

I have created a project using gradle and have created a gradle wrapper. How can I make sure that the project builds and runs on machine who don't have gradle installed?

If you created the project using gradle (i.e. gradle init), then gradle should have placed a gradlew, or gradlew.bat file in the root directory of your project. Use those files to run gradle on another machine.
gradlew can be used on *nix machines, while gradlew.bat is used on windows.
In any case, gradle also creates a gradle/wrapper which contains the gradle jar, and this can be run on any system which has java installed.
See: Difference between using gradlew and gradle

Related

Why is my shellscript execution of a gradle build behaving differently on jenkins than on cli?

When I perform ./gradlew build on command line, gradle downloads and unzips the correct wrapper dist version and continues to download dependencies and build the project.
However when I perform the same within a shellscript on jenkins, it only downloads the gradle wrapper dist zip and tells me there are no dependencies.
How come no dependencies are seen this time ?
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL in 9s
I have already (first) tried using the gradle plugin on jenkins, same result. ANDROID_HOME is the same and set, I am using the same user on the cli.
Java version 8, Gradle 4.1, Android 25, Android build-tools 26.0.2
When i let jenkins invoke a script holding this build command it does work, but not directly. (current quickfix)
Does anyone have an idea what is going wrong ?
It now works, I am not sure what changed to fix this other than the fact i have placed the commands in a function this time, but it is all working as desired.

Gradle Spring boot application not executeable after install/uploadArchives

I want to upload an executable jar/war to a nexus repoistory
When running a gradle build I get a 66 MB jar file containing all required libraries.
However, after running install or uploadArchives, the created jar file now only contains my code and is no long executable.
When creating a war file the only thing missing is Spring's loader package.
The above happens when running gradle tasks separately,
e.g. gradle build
or gradle install
However, if the gradle tasks are run together,
e.g. gradle build install
or gradle build uploadArchives
the executable part is not removed.

How to have Buildship recognize existing projects in Eclipse Mars

I just converted my Maven project to a gradle project. It was a multi project structure:
master-project
pom.xml
---->project1
-------->pom.xml
---->project2
-------->pom.xml
---->project3
-------->pom.xml
I ran a gradle init on it and have this structure now:
master-project
build.gradle
---->project1
-------->build.gradle
---->project2
-------->build.gradle
---->project3
-------->build.gradle
Everything builds fine, and I have been able to get some things done with that I couldn't figure out how to do with Maven, so that's great. Next step was to integrate that into the IDE since the Maven Dependencies are gone since I have removed the pom.xml files.
However the project isn't recognized as a gradle project - and I am not sure how to change that?
In Eclipse Mars it's still recognized as a Maven build, not gradle....
Thanks in advance.
EDIT: I reimported the projects which enabled the plugin for Eclipse. Now I am having weird behavior.
The build works from the command line, however when attempting the same execution from within Eclipse, it fails trying to copy the file dependencies.
For example:
Couldn't copy dependency jakarta-regexp-1.4.jar
java.nio.file.NoSuchFileException: C:\Users\user.m2\repository\jakarta-regexp\jakarta-regexp\1.4\jakarta-regexp-1.4.jar -> build\jfx\app\lib\jakarta-regexp-1.4.jar
I haven't changed the repo from maven yet - just changed the build scripts. This is running from the master project. So I am confused as to why the script would work from the commandline but not from within eclipse.
EDIT 2: Turns out this behavior is also present when running from the command line when the --daemon flag is set. Is there anyway to run the tasks without the daemon in Buildship? Or perhaps a way to fix this issue when the --daemon flag is enabled?
Thanks.
The issue with the build was that there is a leak in the JDK when bundling the JRE with the native app. This only happens when running with the --daemon flag (which all IDEs user). Therefore until this is fixed you will need to run gradle --stop and then run the clean.
The plug in I am using is no longer running the native task when running with --daemon.

Building spring with gradle

I am learning to use git and gradle to build Spring 3.2 on my local system.
I cloned the git repo and used the gradlew command to start the build like so:
gradlew build
I also have the GRADLE_HOME set up and added GRADLE_HOME/bin to my PATH variable.
Every time I start up the build I see a .gradle directory being created in my directory C:\Users\Ayusman and it seems to download gradle binaries.
My questions:
Since I already have gradle installed on my system; why does it have to download gradle?
Can I force gradle to put my dependencies in a specific directory instead of the users folder (like I can specify in maven)?
Can gradle be pointed to pull from a local repo instead of internet?
ad 1. In order to build with your locally installed Gradle, you have to invoke gradle rather than gradlew. The purpose of gradlew (called the Gradle Wrapper) is for everybody to use the same Gradle version and not having to install Gradle manually.
ad 2. To change where Gradle puts dependencies (and other global information), you can set the GRADLE_USER_HOME environment variable.
ad 3. You just need to add another repository declaration to build.gradle. Something like:
allprojects {
repositories {
maven {
url "http://..."
}
}
}
If you want to use this repository for all your builds, you can put the same declaration into ~/.gradle/init.gradle.
Because gradlew invokes the gradle wrapper, which downloads the version of gradle that the build script has been written for, instead of using your version, which might not be compatible. It does that only once, and then reuses the downloaed version. If you want to use your version of gradle, use the gradle command rather than gradlew, but it might not work if you don't have the appropriate version.
AFAIK, this is done by defining the GRADLE_USER_HOME environment variable.
See http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:repositories

Compiling with gradle idea

Hi) when I compile the project are with gradle idea, I should get jar file...?
maybe in the folder dist...
The problem is that I get only two files start.sh and start.cmd
gradle idea doesn't compile the project. It creates project files (*.iws, *.ipr, *l.iml) for IDEA (the IDE from JetBrains). Likewise, there is gradle eclipse to create project files for the Eclipse IDE.
To create a Jar, you can do gradle jar or gradle build (assuming you have the java plugin applied). gradle tasks shows which tasks are available for a given project.
start.sh and start.cmd sound like they are coming from the application plugin. Are you using the application plugin?
The above poster is right that gradle idea simply creates the IntelliJ files that define your modules, src locations, etc. It does NOT compile the project.
Adding apply plugin: 'java' to your build.gradle will allow you to run gradle jar to generate a jar file.

Resources