Gradle wrapper ignores already installed distribution? - gradle

The gradle wrapper distributions are located on my machine under:
C:\Users\Ruperto.gradle\wrapper\dists\gradle-2.10-all
In this folder I already had 2 folder with long names (78v82fsf226usgvgh7q2ptcvif, a4w5fzrkeut1ox71xslb49gst) and now after running gradlew in the command line of Windows it downloaded the same version again and added a new folder to the above path, all of the 3 folders now have the same gradle version inside, same size also, why is this happening?

Gradle Wrapper is downloaded from distribution URL.
If you do not specify the distribution URL, default URL will be used, e.g. https://services.gradle.org/distributions/.
Gradle Wrapper binary is always downloaded once per distribution URL, even if it is exactly the same binary file and it is stored in a directory that is basically hash of the distribution URL.

Related

Gradle Launch4J EXE not trusted by Windows 10

Please note: I have created this GitHub project right here that can be used to perfectly reproduce the problem I'm seeing.
Java 8 here attempting to use Launch4J via the gradle-launch4j Gradle plugin to build a Windows native EXE application. I am doing the development of a Java Swing app on my Mac but the app must run as a Windows EXE on Windows 10. I am also using ShadowJar to build my self-contained "fat jar".
I can build my (Swing) app's fat jar and then run it on my Mac via java -jar build/lib/myapp.jar. It starts and runs no problem.
Here is my Gradle config for Launch4J:
launch4j {
mainClassName = 'com.example.windows.hello.HelloWindowsApp'
icon = "${projectDir}/icon.ico"
jdkPreference = 'jdkOnly'
initialHeapSize = 128
jreMinVersion = '1.8.0'
jreMaxVersion = '1.8.9'
maxHeapSize = 512
stayAlive = false
bundledJre64Bit = true
bundledJrePath = '../hello-windows/jre8'
}
When I run ./gradle clean build shadowJar createExe createDistro it produces:
hello-windows.zip/
hello-windows.exe --> The Windows EXE built by the 'createExe' task
lib/* --> The lib/ dir for the EXE that is also built by the `createExe` task
jre8/ --> OpenJDK JRE8 (copied from the libs/jre8 dir)
So I copy that ZIP file and port it over to a Windows 10 (64-bit) machine. I extract the ZIP and run the EXE by double clicking it inside Windows Explorer (which I can confirm does see the EXE as an Application type). First I see this:
Why is this happening? Are there any Launch4J configurations/settings I can change so that this doesn't happen?
Thanks in advance!
You need to sign the executable created by launch4j as described here to prevent SmartScreen from blocking it to be run. See also the related discussion in the support forum.
Your first question is more like a Windows question. When you unzip an application from a zip file, Windows will naturally mark it as unsafe, in fact if you check the application properties tab, you will see a checkbox where you can remove that unsafe attribute. It's same as running chmod+x for an executable script in Linux.
For the second part, I assume you are using the gradle plugin for Launch4j, there are two main ways to configure Launch4j assuming your project folder is structured commonly with the jre library in the same folder containing your executable folder.
By specifying the path only like
../jre
By specifying the full relative path
../jre/bin/javaw.exe
Your generated xml at the end should look like this in the first case.
<jre>
<path>../jre</path>
</jre>
The main point is that the path to JRE is relative to the position of the executable not the current directory. In this case, we step back one directory from the executable folder to the folder containing jre.
Try setting the bundledJrePath in your build.gradle to just jre8:
launch4j {
...
bundledJrePath = 'jre8'
}
Because that is in your case the relative path where the jre is when extracting the zip.
http://launch4j.sourceforge.net/docs.html
<path>, <minVersion>, <maxVersion>
The <path> property is used to specify the absolute or relative path (to the executable) of a bundled JRE, it does not rely on the current directory or <chdir>. Note that this path is not checked until the actual application execution
Beware that the path must not contain the /bin/javaw.exe.
When running the exe with the debug flag like this
hello-windows.exe --l4j-debug
then it will create a file launch4j.log in the same directory.
There you can check that the correct jre is picked up, for example:
...
Bundled JRE: jre8
Check launcher: C:\Users\IEUser\Downloads\hello-windows\jre8\bin\javaw.exe (OK)
...
I upvoted the answer above from sschuberth, as that is the best answer to your question. Signing the executable will make SmartScreen happy.
As addition I would rather prevent trying to create an executable, even signing it, best to create a MSI. For example by using Javapackager. See also this question. That guy created his own tool after using Nullsoft.
It is very cumbersome to get an executable accepted by every virus scanner around the world. I have the experience of using WIX Toolset to create an MSI and wrapped it into a bootstrapper executable, signed it using the company signing certificate. However in the end I had to send requests to McAfee, Norton, Avast, AVG, KasperSky and Trend Micro. Gladly all accepted it over time, only Trend Micro never even responded.

Where m2 file is stored when installing apache maven on a unix box

I downloaded maven gz file, unzipped same, but i dont know where the m2 is stored. I imagine im missing a step but i cant see what one?
Is there aninstall script etc?
[root#atddpvm5 apache-maven-3.5.4]# cd /var/tmp/apache-maven-3.5.4/
[root#atddpvm5 apache-maven-3.5.4]# ls
apache-maven DEPENDENCIES doap_Maven.rdf LICENSE maven-builder-
support maven-core maven-model maven-plugin-api
maven-resolver-provider maven-settings-builder NOTICE README.md
CONTRIBUTING.md deploySite.sh Jenkinsfile maven-artifact maven-compat
maven-embedder maven-model-builder maven-repository-metadata maven-
settings maven-slf4j-provider pom.xml src
By default the .m2 folder is stored in the home folder of the user. In this case since you are using root, the path is most likely /root/.m2. You also have to use the -a switch with ls to see that folder, since it's a hidden folder (it starts with a .). Note that the folder will only be created on the first usage of Maven, i.e. when you call a maven command on a maven project, like mvn clean install.
Additionally it looks like you have downloaded the source distribution of Maven, which only makes sense if you want to work on Maven itself. You might want to download the binary distribution, if you just want to use it.

How Do You Specify Where The Gradle Wrapper Installs Gradle?

I have an off the shelf application that ships a version of gradle with it. It also has scripts that are hard coded to set GRADLE_HOME to this location.
I want to zip up this dir, put it in nexus and replace it with the gradle wrapper.
How do I configure the gradle wrapper to download this zip from nexus and extract it to a specific location in the project?
EDIT: In the gradle-wrapper.properties I have
distributionPath=wrapper/gradle
However, I end up with it being unzipped to
...\wrapper\gradle\gradle-2.3-bin\8gn7esgljqyucijpbynjk93oc\gradle-2.3
How do I get it to unzip to the path I specified and not to the subdirs?
The location to which Gradle gets unpacked is a combination of the distributionBase and distributionPath properties in gradle-wrapper.properties file. The location specified by distributionPath will always be considered as relative to distributionBase. The only available values for distributionPath are GRADLE_USER_HOME and PROJECT. Even when using PROJECT the wrapper will still generate the folder structure you see above.
If you want to control this more precisely I'd suggest not relying on the wrapper to do this and instead add a task to your build specifically for this purpose.

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

How to use gradle zip in local system without downloading when using gradle-wrapper

I'm trying to build a gradle project with gradle-wrapper (gradlew).
When I build with ./gradlew build, it outputs text
Downloading http://services.gradle.org/distributions/gradle-1.11-bin.zip
And I already got gradle-1.11-bin.zip downloaded separately and I don't want to be downloading it again when I build.
So, where shall I put gradle-1.11-bin.zip in my project or system so that I don't have to download again?
gradle/wrapper/gradle-wrapper.properties is as following.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip
And I've tried copying gradle-1.11-bin.zip into gradle/wrapper/dists which didn't solve the problem.
From gradle-wrapper documentation, I found in section 61.1. Configuration
If you don't want any download to happen when your project is build
via gradlew, simply add the Gradle distribution zip to your version
control at the location specified by your wrapper configuration. A
relative URL is supported - you can specify a distribution file
relative to the location of gradle-wrapper.properties file.
So, I changed distributionUrl property in gradle/wrapper/gradle-wrapper.properties to
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-1.11-bin.zip
Then, I made a copy of gradle-1.11-bin.zip in gradle/wrapper/.
Then, ./gradlew build downloaded local copy of zip and built the project.
Here's a real-world example:
mkdir -p $HOME/dev
cd $HOME/dev
git clone https://github.com/oss-review-toolkit/ort
cd ort/gradle/wrapper
wget https://services.gradle.org/distributions/gradle-7.5.1-bin.zip
sed -i 's/distributionUrl=.*/distributionUrl=gradle-7.5.1-bin.zip/' gradle-wrapper.properties
cd ../..
./gradlew installDist
Modifty the gradle/gradle-wrapper.properties
Windows:
distributionUrl=file\:/d:/gradle-2.2.1-all.zip
linux:
distributionUrl=file\:/tmp/gradle-2.2.1-all.zip
Just drag downloaded gradle file in your browser address bar and then copy address from address bar and change gradle/wrapper/gradle-wrapper.properties as following:
distributionUrl=ADDRESS THAT COPY FROM YOUR BROWSER
example:
distributionUrl=file:///E:/gradle/gradle-4.1-all.zip
or you can copy gradle.zip file to wrapper folder then use relative path:
distributionUrl=gradle.zip
This is what I did to avoid editing all gradle wrapper for current and future projects.
Locate your gradle-wrapper.properties in your project folder (eg. ./gradle/wrapper/gradle-wrapper.properties)
open the file with a text editor like Sublime Text to locate the distributionUrl line (eg. distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-bin.zip
The gradle binary archive needed is gradle-2.10-bin.zip. Another version is gradle-2.10-all.zip that includes everything including source code and documentation.
Please note each project ships with different versions of gradle distributions and you can change the version to the one you have (gradle-x.xx-XXX.zip) that include the binary. (eg. gradle-2.11-bin.zip | gradle-2.11-all.zip ).
Execute gradlew.bat on window or gradle on linux to start the wrapper to build the project.
It will begin downloading the gradle-2.10-bin.zip to the .gradle\wrapper\dists in your home directory (eg.C:\Users\Sojimaxi\.gradle\wrapper\dists\gradle-2.10-bin). This download happens just once for each specified gradle version.
If you already downloaded the archive before you can terminate the download using Ctrl+C
Go into the gradle download location C:\Users\Sojimaxi\.gradle\wrapper\dists\gradle-2.10-all\78v82fsf226usgvgh7q2ptcvif copy your own copy of gradle-2.10-bin.zip into that directory then delete the gradle-2.10-all.zip.part in that directory.
That's all. Go back to your project directory to execute gradlew.bat and it will use your local copy instead of downloading a new one.
This solution didn't work for me but help me to get the right way so if you want install gradle offline follow these steps:
1- at your project under gradle directory open this file (gradle-wrapper.properties)
2- at last line you will find the gradle version, download that version or copy the file from another pc
distributionUrl=http\://services.gradle.org/distributions/gradle-3.3-bin.zip
Download Link will be like this: http://services.gradle.org/distributions/gradle-3.3-bin.zip
3- open this location
C:\Users\userName.gradle\wrapper\dists\gradle-3.3-all
and ensure that is only one folder (the name doesn’t matter it different at devices) if there any other folders delete all of them and press gradle sync on android studio which will generate another folder automatic with a random name.
4- open that folder and ensure that has only the last two files in the screenshot.
5- move the zip file that you downloaded into that folder
6- press sync gradle on android studio again suppose that gradle will work fine.
I found another easiest way to do this just started my XAMPP server and then made a folder gradle inside htdocs. I added the zipped file gradle-4.4-all.zip inside that folder. Changed the distribution url to distributionUrl=http\://localhost/gradle/gradle-4.4-all.zip
I restarted android and the syncing completed without any issue.
copy your path wher you put the file gradle-5.0-rc-5-bin.zip
example:
path C:/My doc/tools
if you have some spaces in your path change it with %20
file:///C:/My%20doc/tools/gradle-5.0-rc-5-bin.zip
and execute the command:
$ gradlew wrapper --gradle-version 5.0-rc-5
I download to
C:\data\Setup\Development\Gradle 2.11\gradle-2.11-all.zip
inside Eclipse, I declare:
Then I create new Gradle project (with wrapper) very fast, no need download. (Easy more than this solution)
create local server to mock https download(maybe a little complex),but it work
1. install tomcat then unzip and exec E:\apache-tomcat-8.5.4\bin\startup.bat
2.put gradle-2.14.1-all.zip to E:\apache-tomcat-8.5.4\webapps\ROOT\distributions
3.change url like this distributionUrl=http\://localhost:8080/distributions/gradle-2.14.1-all.zip
now run as usual
// Do not use android 8 as it will keep downloading grade distribution use grade 7
ionic cordova platform add android#8.0.0
// This will run
ionic cordova platform add android#~7.1.1 --save
Then run below and this time it should get success( Worked for me)
ionic cordova build android

Resources