How can I pass this params to gradle command
e.g.
./gradlew clean build org.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
gives error as
* What went wrong:
Task 'org.gradle.jvmargs=-Xmx2048m' not found in root project
What you have written works if you put it in a gradle.properties file. If you want to use it on the command line, you first have to add a -D (see command line interface in the user guide) but also quote the argument as it contains spaces. E.g.
./gradlew clean build "-Dorg.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError" -Dfile.encoding=UTF-8
-Dorg.gradle.jvmargs="-Xmx8192M -Dkotlin.daemon.jvm.options\\=\"-Xmx8192M\""
works for me
Related
I have created a module com.company.ep that is located in the source folder com.company.ep. (Yes, I have removed src from the build path and deleted it!) Inside the source folder, I have a couple of packages as the following:
com.company.ep <--- root source folder
com.company.ep.main <--- package 1
com.company.ep.model <--- package 2
com.company.ep.view <--- package 3
// ... more packages
module-info.java
The main class is located in the package com.company.ep.main.Main. In my module-info.java, I have configured the dependencies:
module com.company.ep {
exports com.company.ep.main;
exports com.company.ep.model;
exports com.company.ep.view;
// ... more exports
requires javafx.controls;
requires javafx.graphics;
}
When I tried to launch my program, eclipse told me that:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found, required by com.company.ep
So, I tried to run it on the command prompt:
java -p d:\Applications\openjfx-sdk-11\lib;bin -m com.company.ep/com.company.ep.main.Main
bin is the output folder of eclipse, and it worked.
So, I went to Properties → Run/Debug Settings → Main → Show Command Line, it showed:
D:\Applications\openjdk-11.0.1\bin\javaw.exe -Dfile.encoding=UTF-8 -p "D:\Development\Eclipse-Workspace\MyProject\bin" -classpath "D:\Applications\openjfx-sdk-11\lib\javafx.base.jar;D:\Applications\openjfx-sdk-11\lib\javafx.controls.jar;D:\Applications\openjfx-sdk-11\lib\javafx.fxml.jar;D:\Applications\openjfx-sdk-11\lib\javafx.graphics.jar;D:\Applications\openjfx-sdk-11\lib\javafx.media.jar;D:\Applications\openjfx-sdk-11\lib\javafx.swing.jar;D:\Applications\openjfx-sdk-11\lib\javafx.web.jar;D:\Applications\openjfx-sdk-11\lib\javafx-swt.jar" -m com.company.ep/com.company.ep.main.Main
I have created a user library with all JARs added, and the library is added to the project's Modulepath.
Then I have tried to set the module path explicitly in VM arguments in Run/Debug Settings: -p D:\Applications\openjfx-sdk-11\lib, I'd still no luck.
My questions are:
Why javaw.exe?
Why classpath? As my library is added as a module-path entry.
How to configure the module dependencies in eclipse.
I am not sure if I have configured eclipse correctly, or whether it is probably a problem of OpenJDK as it worked when I worked on another computer with Oracle Java SE installed.
Thank you!
The explanation of why Eclipse fails on running your modular project can be found in the OpenJFX docs for Eclipse (modular from IDE section).
As it was already mentioned:
Being a modular project, and since we already added the JavaFX SDK library to the module-path, there is no need to add any VM arguments.
But if you run on Eclipse you will get the mentioned error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found, required by hellofx
So why is it failing??
As explained in the docs:
This exception happens because the Eclipse ant task overrides the module-path
How does this happen??
Checking the command line applied (Show Command Line from Run Configurations...), you can find out why:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx \
-classpath $PATH_TO_FX \
-m hellofx/org.openjfx.MainApp
If you copy it and paste it and run it in a terminal, it will fail of course with the same message. The reason is that Eclipse doesn't add the JavaFX library to the module path.
If the task generates the wrong arguments, let's try to fix it by adding our own VM arguments by editing Run configurations... and adding -p $PATH_TO_FX:bin/hellofx.
But if you run it, it will fail again.
Let's check why, with Show Command Line from Run Configurations...
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p $PATH_TO_FX:bin/hellofx \
-p bin/hellofx \
-classpath $PATH_TO_FX \
-m hellofx/org.openjfx.MainApp
As you can see, the user's VM arguments are added before the default ant task arguments, so there are two -p (--module-path) options, and the first one (the user's one with the JavaFX jars) is overridden by the second one (only the project's module), so, again, the JavaFX jars are not added to the module path, and hence you get the error.
So how can we fix it??
As mentioned in the linked documentation, the possible fix is:
To prevent this issue click on Run -> Run Configurations... -> Java Application -> Dependencies, select Override Dependencies... and add -p /path-to/javafx-sdk-11/lib:bin/hellofx, and press Override.
With this solution, you can see it works, and you can check the command line:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p $PATH_TO_FX:bin/hellofx \
-p bin/hellofx \
-classpath $PATH_TO_FX \
-p /path-to/javafx-sdk-11/lib:bin/hellofx \
-m hellofx/org.openjfx.MainApp
Basically we are adding again the "right" module path option, after all the failed ones.
While now the project runs, the solution is obviously not nice.
Here you can find a sample referred from the OpenJFX documentation.
EDIT
Based on #kleopatra comments, another workaround to make it work is the following:
For some reason, the library JavaFX11 (that contains modular jars) is not scanned and Eclipse doesn't include those jars into its -p option, but into the classpath:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx \
-classpath $PATH_TO_FX \
...
But, if you add those jars directly to the module path, it will do add them, and this will run fine:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx:$PATH_TO_FX/javafx.base.jar:...:$PATH_TO_FX/javafx.controls \
...
Then with this there is no more need to override the dependencies.
EDIT 2
As #mipa points out in a comment, there was a bug filed on this issue, and it has already been solved. I've tested it with Eclipse 2018-12 M2 (4.10.0M2) Build id: 20181108-1653, and it works with the JavaFX11 library only (as it should):
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx:$PATH_TO_FX/javafx.base.jar:... \
-m hellofx/org.openjfx.MainApp
24.3 Application Property Files uses the following command to add an application property spring.config.name:
$ java -jar myproject.jar --spring.config.name=myproject
How can I do this with gradle bootRun?
BootRun task extends JavaExec task: https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/gradle-plugin/api/org/springframework/boot/gradle/tasks/run/BootRun.html
Since Gradle 4.9, the command line arguments can be passed with --args. For example, if you want to launch the application with command line arguments foo --bar, you can use:
gradle bootRun --args='--spring.config.name=myproject'
I have a bash script in my maven project to run my application. I compiled my project with two different type of variable usage in my bash script:
1.
#!/bin/bash
MAIN_PATH=`dirname $0`
cd $MAIN_PATH
MAIN_PATH=..
MAINCLASS="${component.mainclass}"
LIB_PATH="$MAIN_PATH/lib"
JACOCO_VERSION="${jacoco.version}"
JACOCO_PATH=$LIB_PATH
JACOCO_OPTS=-javaagent:$JACOCO_PATH/jacoco-javaagent-$JACOCO_VERSION.jar=jmx=true,output=tcpserver,address=*,port=6302,includes=*
JAVA_OPTS="${filter.component.java.opts}"
GC_OPTS="${filter.component.gc.opts}"
CLASSPATH=""
CLASSPATH=$MAIN_PATH/config
for f in $MAIN_PATH/lib/*.jar; do
CLASSPATH=$CLASSPATH:$f
done
echo "java -classpath $CLASSPATH $MAINCLASS"
java $GC_OPTS $JAVA_OPTS -classpath $CLASSPATH $MAINCLASS $*
2.
MAIN_PATH=`dirname $0`
cd ${MAIN_PATH}
MAIN_PATH=..
MAINCLASS="${component.mainclass}"
LIB_PATH="$MAIN_PATH/lib"
JACOCO_VERSION="${jacoco.version}"
JACOCO_PATH=${LIB_PATH}
JACOCO_OPTS=-javaagent:${JACOCO_PATH}/jacoco-javaagent-${JACOCO_VERSION}.jar=jmx=true,output=tcpserver,address=*,port=6302,includes=*
JAVA_OPTS="${filter.component.java.opts}"
GC_OPTS="${filter.component.gc.opts}"
CLASSPATH=""
CLASSPATH=${MAIN_PATH}/config
for f in ${MAIN_PATH}/lib/*.jar; do
CLASSPATH=${CLASSPATH}:${f}
done
echo "java -classpath $CLASSPATH $MAINCLASS"
java ${GC_OPTS} ${JAVA_OPTS} -classpath ${CLASSPATH} ${MAINCLASS} $*
Filters are as following:
filter.component.java.opts=-mx4096M $JAVA_OPTS $JACOCO_OPTS
filter.component.gc.opts=-XX:+UseG1GC
jacoco.version and component.mainclass are defined in the pom.xml:
<jacoco.version>0.7.6.201602180812</jacoco.version>
<component.mainclass>MyAppStarter</component.mainclass>
I build the maven project with this command:
mvn clean install -X
If I use the first mentioned way of variable definition, the ${JAVA_OPTS} passing to java will be substituted with -mx4096M after build, but in the other way $JAVA_OPTS will be changed to -Xmx3072m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true.
There is no difference between $JAVA_OPTS and ${JAVA_OPTS} in linux bash scripting; what is the difference between these two for java or maven?
EDIT 1:
For the last variable usage I mentioned, the variable substitution for JAVA_OPTS happens during build. I mean for the second way, when the maven build completes, the last line does not contain JAVA_OPTS anymore, but with the first method, no change occurs.
For the first way the last line after build is:
java $GC_OPTS $JAVA_OPTS -classpath $CLASSPATH $MAINCLASS $*
And for the seconds one, I receive this as last line:
java ${GC_OPTS} -Xmx3072m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true -classpath ${MAINCLASS} $*
EDIT 2:
I have put these two echo commands in both final scripts after the line JAVA_OPTS="${filter.component.java.opts}":
echo "test 1 >> "$JAVA_OPTS
echo "test 2 >> "${JAVA_OPTS}
And the result for both is the same:
test 1 >> -mx4096M -javaagent:../lib/jacoco-javaagent-0.7.6.201602180812.jar=jmx=true,output=tcpserver,address=*,port=6302,includes=*
test 2 >> -mx4096M -javaagent:../lib/jacoco-javaagent-0.7.6.201602180812.jar=jmx=true,output=tcpserver,address=*,port=6302,includes=*
EDIT 3:
I checked my environment variables before build with an echo command:
echo 'JAVA_OPTS: '${JAVA_OPTS}
It turns out that JAVA_OPTS is set in my environments:
JAVA_OPTS: -Xmx3072m -XX:MaxPermSize=1024m -Djava.net.preferIPv4Stack=true
${...} syntax used by maven resources plugin:
These variables, denoted by the ${...} delimiters, can come from the system properties, your project properties, from your filter resources and from the command line.
so at last line of second script, when maven resource plugin see ${JAVA_OPTS} It searches in environment to find JAVA_OPTS and then substitutes it with that.
I am working on a Java project with Gradle Wrapper (gradlew). I use Ubuntu Linux as my OS. When I run "gradle" it runs, and gives me information. But when I run "gradlew", it outputs as:
No command 'gradlew' found, did you mean:
Command 'gradle' from package 'gradle' (universe)
gradlew: command not found"
I did my research, I have the JDK, and I did sudo apt-get install gradle. How can I fix it?
The error is:
gradlew clean jpackage
Output:
bash: gradlew: command not found...
Linux and macOS
As noted in the comments, just running
./gradlew
worked for me. Adding the ./ tells it to look in the current directory since it isn't in the path.
Windows PowerShell
.\gradlew
The Gradle wrapper needs to be built. Try running gradle wrapper --gradle-version 2.13.
Remember to change 2.13 to your Gradle version number. After running this command, you should see new scripts added to your project folder. You should be able to run the wrapper with ./gradlew build to build your code.
Please refer to this guide for more information: Building Java Projects with Gradle
Running this Bash command works for me by running chmod 755 gradlew as sometimes file properties changed upon moving from one OS to another (Windows, Linux and Mac).
If you are using Mac, try giving root access to gradlew by doing:
chmod +x ./gradlew
From Mac,
Nothing is working except the following command:
chmod 777 gradlew
Then
./gradlew
The same problem occurs to me...
I check the file wrx permissions with:
$ls -l ./gradlew -> -rw-rw-r-- (no execute permission)
So I use command $chmod +x ./gradlew and this problem is solved.
In addition to Suragch's answer:
Linux and macOS
./gradlew clean
Windows PowerShell
.\gradlew clean
Windows cmd
gradlew clean
You must have the Gradle wrapper available locally before using gradlew. To construct that
gradle wrapper # --gradle-version v.xy
Optionally, pass the Gradle version explicitly. This step produces the gradlew binary. And then you should be able to
./gradlew build
For Ubuntu (Linux) users:
Doing bash ./gradlew build works, but ./gradlew build does not work.
For me, the issue was it was on the NTFS file system, and Linux does not let you execute a script from NTFS.
Try moving the code from NTFS to a Linux partition. Then ./gradlew build should work.
If you are using Visual Studio Code with Flutter, you should find it in your app folder, under the android folder:
C:\myappFolder\android
You can run this in the terminal:
./gradlew signingReport
The first thing is you need to run the gradle task that you mentioned for this wrapper. Example:
gradle wrapper
After running this command, check your directory for the gradlew and gradlew.bat files. gradlew is the shell script file, and it can be used in Linux and macOS. gradlew.bat is the batch file for the Windows OS. Then run,
./gradlew build (Linux and Mac). It will work.
Issue: Couldn't find gradlew at path jenkins
In my case, within the Jenkins CI for flutter project, I have to first run the flutter build app command, and then it automatically generated a gradlew file. And the above issue is resolved.
I put this command in my Jenkins file:
flutter build apk
In a Flutter project, don't forget to go to 'android' folder with 'cd android'.
Then you can run a command like './gradlew build' or './gradlew clean' on it (macOS).
If the answer marked as correct does not work, it is because you need to identify yourself as a super user.
sudo gradle wrapper --gradle-version 2.13
It worked for me.
I faced the same issue, but after some tries I found
it was happening because I was trying to create build in Git Bash,
instead of CMD with system administrator access.
If you create build with a command prompt, run as administrator. Then the build will get created.
If you are trying to run this command for a Flutter app, then go to the android folder first by cd android. And then use the command, and it should work.
cd android
./gradlew signingReport
I use IntelliJ IDEA and in Windows in the terminal I type:
gradlew.bat run
It is working for me.
Instead of gradlew assembleRelease, use ./gradlew assembleRelease.
I had to do dos2unix * in my current folder to make it work.
Ubuntu
Error:
Command 'gradlew' not found, did you mean:
command 'gradle' from snap gradle (7.2)
command 'gradle' from deb gradle (4.4.1-13)
See 'snap info ' for additional versions.
Use this command:
./gradlew signingReport
I've just installed sbt on my Windows Vista machine, following the guide on github wiki, using a sbt.bat script containing
set SCRIPT_DIR=%~dp0
java -Dfile.encoding=UTF8 -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled
-XX:MaxPermSize=256m -jar "%SCRIPT_DIR%sbt-launch.jar" %*
When I run sbt in an empty directory, I get
L:\foo>sbt
L:\foo>set SCRIPT_DIR=L:\lib\sbt\
L:\foo>java -Dfile.encoding=UTF8 -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled
-XX:MaxPermSize=256m -jar "L:\lib\sbt\sbt-launch.jar"
[info] Set current project to default-058262 (in build file:/L:/foo/)
>
instead of expected prompt to create a new project. What am I doing wrong?
In contrast with SBT 0.7, SBT 0.10+ does not prompt you for project creation, but assumes some default configuration and deploy its own working directories.
If you want to provide you settings, you must add an build.sbt file or a full configuration.
Add the np plugin. This replaces the previous functionality.
https://github.com/softprops/np