Gradle Wrapper not responding to commands - gradle

On my Linux machine in my root project directory I have the Gradle Wrapper
Project
|
+ src
|
+ gradlew
and when I run any command with gradlew there is no output, like for example when I print the version, there is no version printed
./gradlew --version
or when I check tasks, no tasks are displayed
./gradlew --tasks
or when I try to build the project, no out/ directory is created
./gradlew deploy
but when I click
Build > Build Project
in my Intellij IDE, the project does build, just not when I try to use Gradle from the command line.
So I have no idea what's going on with my gradle wrapper. Am I using the wrapper incorrectly?

My gradle wrapper which is just a Bash script, was empty ... somehow it's contents were deleted, so the script was running and nothing was happening. Good times.

It happened to me as well, the script was totally empty. The fix for me was to go to the gradle tab in IntelliJ and click on "Wrapper" under "Build setup".
After this my gradlew script got properly initialized.

Related

Update gradle version if necessary on autodeployment

I updated gradle locally by changing the version in my build.gradle file here:
wrapper {
gradleVersion = '5.6.1'
}
Next I was not able to build directly due to errors, but my IDE noticed that the version of gradle has changed and offered to install it through a popup. After that everything worked.
When I pushed my changes to my autodeployment tool it currently builds the project by executing:
call gradlew clean war
But I'm getting the same errors and this time there's no smart IDE to come to the rescue :D Therefore my question:
How can I make sure my gradle always updates to the version that is defined in build.gradle before trying to build?
The version of Gradle that is used by the wrapper script is the one defined in the file gradle/wrapper/gradle-wrapper.properties.
When you want to update Gradle, you could go manually changing that file, but this won't update the actual wrapper script and jar file. So it is a better practice to run ./gradlew wrapper, which will update gradle-wrapper.properties and, if needed, the other support files as well.
To tell the wrapper task which version you want to use upgrade to, you can either use a command line parameter, or do what you are doing and keep the version in the build.gradle file (this is always what I do as well).
I usually run the wrapper task twice: first to update the version and second to both download the new version and then regenerate the scripts from this new version.
Remember to commit all files changed by the wrapper task, which could be gradlew, gradlew.bat and the two files in the gradle/wrapper folder.

How do I get rid of the Executing/Progress Bar when running a Gradle application?

I am trying to build a console based application but whenver I run
./gradlew run
I get thr progress bar which looks like this:
<=========----> 75% EXECUTING [29s]
Is there anyway I can remove this bar (which hangs out until the application ends)? Or is there a better way to write console base applications with gradle?
The version is 4.3.1
You can configure the Gradle log format using console command line parameter, as described here : https://docs.gradle.org/current/userguide/command_line_interface.html#rich_console
Try with : ./gradlew run --console=plain
Another way of doing this seems to be by setting the TERM environment variable to dumb.
Try TERM=dumb ./gradlew run
To make it a default behavior, add org.gradle.console=plain to gradle.properties file (prerequisite Gradle version is more than 4.x).
For one time execution add --console=plain flag to your command.
I know your question is specific to using the gradle wrapper, but if you're using the Gradle Tooling API, you can control the color output via
setColorOutput. Combined with the --quiet argument (set via withArguments), this results in plain-text output.

Error: Unable to access jarfile build/libs/gs-spring-boot-0.1.0.jar?

I follow the instructions in https://spring.io/guides/gs/spring-boot/#scratch, but when it says to run:
./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
the build fails with the above error.
There is message before the failure that says:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8.1/userguide/command_line_interface.html#sec:command_line_warnings
but everyone online says that's just a warning.
The build doesn't appear to create or download build/libs/gs-spring-boot-0.1.0.jar.
Currently completely blocked on first attempt to use Gradle.
I just had this problem.
The tutorial is in error in what you need to run. It should be
$ gradlew build && java -jar build/libs/gs-rest-service-0.1.0.jar
I think that they updated the code, but forgot to update the tutorial.
I had the same issue when build a simple project with Maven on Intellij IDEA. (Ubuntu 18.04.2).
Just typed terminal (in project directory):
$ sudo mvn package
$ java -jar ./target/(your-project-name)-(<version> at pom.xml).jar
For example my project name is hello-world-spring and version name in pom.xml is <version>0.0.1-SNAPSHOT</version>, I have to type:
$ sudo mvn package
$ java -jar ./target/hello-world-spring-0.0.1-SNAPSHOT.jar
Maybe this method can work for gradle as well.
Please check the path of the jar file build/libs/gs-spring-boot-0.1.0.jar. For your case, the jar might be in a different folder. If your code is in a module in the main project, then the jar will be in the build folder of the module.
If you git clone the repo, then the tutorial works. If you "To start from scratch, move on to Build with Gradle.", then the tutorial doesn't work. There are missing setup steps.
I got the same issue and I changed the command to java -jar target/rest-service-0.0.1-SNAPSHOT.jar (I checked the .jar file in target folder and found that the file name was incorrect).
Parent folder of my project was having spaces in it's name, i changed it to the underscore and it worked.
Looked at the command line as it was in the official guide:
./gradlew clean build && java -jar build/libs/gs-actuator-service-0.1.0.jar
First, the above command line has two parts:
(1) ./gradlew clean build //Use gradle wrapper to build
(2) java -jar build/libs/gs-actuator-service-0.1.0.jar //To run an application packaged as a JAR file
Now, one might run into issues with one part or both parts. Separating them and running just on thing at a time helped troubleshoot.
(1) didn't work for my Windows, I did the following instead and that built the application successfully.
.\gradlew.bat clean build
Now moving to (2) java -jar build/libs/gs-actuator-service-0.1.0.jar
It literally means that "Run a jar file that is called gs-actuator-service-0.1.0.jar under this directory/path: build/libs/" Again, for Windows, this translates to build\libs\ , and there's one more thing that may catch you: The jar file name can be slightly different depending on how it was actually named by the configuration in initial/setting.gradle:
rootProject.name = 'actuator-service'
Note that the official guide changed it from 'gs-actuator-service' to 'actuator-service' in their sample code but hasn't updated the tutorial accordingly. But now you know where the jar file name comes from, that doesn't matter anymore, and you have the choice to rename it however you want.
Having all the factors adjusted, below is what eventually worked in my case:
java -jar build\libs\actuator-service-0.0.1-SNAPSHOT.jar
or
java -jar C:\MyWorkspace\Spring\gs-actuator-service\initial\build\libs\actuator-service-0.0.1-SNAPSHOT.jar //with fully qualified path
If you are curious where does "-0.0.1-SNAPSHOT" come from, here it is:
in build.gradle
version = '0.0.1-SNAPSHOT'
Again, you have the choice to modify it however you want. For example, if I changed it to 0.0.2-SNAPSHOT, the command line should be adjusted accordingly
java -jar build\libs\actuator-service-0.0.2-SNAPSHOT.jar
Reference: https://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html
Because you are trying to execute .jar file that doesn't exist. After building the project go to ./build/libs and check the name of freshly built .jar file and then in your project directory run:
./gradlew build && java -jar build/libs/name-of-your-jar-file.jar
or you can set version property to empty string in your build.gradle file
version = ''
after that:
./gradlew build && java -jar build/libs/your-project-name.jar
For Windows, these commands solved the problem: "Error: Unable to access jarfile springboot.jar":
cd target
java -jar springboot-0.0.1-SNAPSHOT.jar
run ./mvnw package
Now a folder named target is created and you can see a jar file inside it.
then execute java -jar target/<jarfilename>

Continuous Gradle build

I'm a relatively new user with Gradle, I'm working for the first time on a project (and first time with JHipster as well).
To run my application through the terminal, I execute the following command:
gradlew.bat
But at each new modification I have to kill the application ctrl + c and run it again.
I already tried using the command gradlew.bat -t build -x test (I don't want to run test each time) and gradlew.bat --continue, but both did not work.
As the bootRun task, which is the default task gradle doesn't know when to start watching, so it is not possible with gradle only. Using your ide (e.g. intellij) and the springboot devtools it is possible.
Start the application from our ide
Make changes in the code
In intellij press ctrl + F9 to compile the code and the application should restart
When you want to do it with gradle only you need two terminals and start e.g. javaCompile in continuous mode and bootRun in another terminal. The boot devtools will take care of restarting the application when it detects the newly compiled files.
gradlew compileJava -t in on terminal
gradlew bootRun in another terminal

Go CI does not recognize build file for gradle

I have setup GO CI pipeline for continuous integration in my project. I tried to add a project that is built using gradle. I tried a add gradle task for building my application.
While executing build it shows that
FAILURE: Build failed with an exception.
* What went wrong:
Task 'build' not found in root project 'Gradlepipelinejob'.
I tried to add defaultTasks 'clean', 'compile' to the parent build.gradle file. But still the same error exists. Someone pls help me in resolving this issue.
I think 'build' should be in Command section, rather than arguments. Even after that if it doesn't works, try executing build commands in the agent terminal(or any command prompt).This will let you figure out whether the error is in server or agent.
GO CI runs the command in the code checkout directory so please check if your gradle file is present or not in that directory

Resources