I have 2 relatively simple Gradle 6.1.1 configs, one is using https://plugins.gradle.org/plugin/com.github.node-gradle.node to build a react app, and the other one is based on https://plugins.gradle.org/plugin/com.bmuschko.tomcat and runs a simple wicket app in embedded tomcat.
The 1st config for npm task is:
apply plugin: 'com.github.node-gradle.node'
node {
version = '12.16.0'
download = true
workDir = file "$project.buildDir/nodejs"
}
task "npmBuild"( type:NpmTask ) {
args = [ 'run', 'build' ]
}
and produces the following output in Windows 10:
>gradlew.bat npmBuild
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :npmBuild
> layer-selection#0.1.0 build .....
> react-scripts build
Creating an optimized production build...
Compiled with warnings.
...
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
File sizes after gzip:
90.99 KB build\static\js\2.17f9cda1.chunk.js
28.68 KB build\static\css\2.2f7f14af.chunk.css
3.43 KB build\static\js\main.1150707e.chunk.js
778 B build\static\js\runtime-main.989054bd.js
177 B build\static\css\main.f7c0afb8.chunk.css
...
Find out more about deployment here:
bit.ly/CRA-deploy
at this point the tasks lasted approx. 20 seconds, then it hangs for 3 min with CPU-load below 1% and continues:
BUILD SUCCESSFUL in 3m 18s
2 actionable tasks: 1 executed, 1 up-to-date
The strange thing is that running the same config on similar project on another Win10 machine results in clean run w/o freezes.
Also the tasks:
task "npm-install"( type:NpmTask ) {
args = [ 'install' ]
}
task "npm-set-proxy"( type:NpmTask ) {
args = [ 'config', 'set', 'https-proxy', 'http://www.www.www:80/' ]
}
show the same 3-extra-minutes behavior.
The 2nd config looks like:
apply plugin: 'com.bmuschko.tomcat'
ext.tomcatVersion = '9.0.30'
dependencies {
// some deps
tomcat "org.apache.tomcat.embed:tomcat-embed-core:$tomcatVersion",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:9.0.0.M6",
"org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion",
"org.apache.tomcat:tomcat-jdbc:$tomcatVersion",
"org.apache.tomcat:tomcat-dbcp:$tomcatVersion"
'org.postgresql:postgresql:42.2.12'
'log4j:log4j:1.2.17'
}
tomcat {
httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol'
ajpProtocol = 'org.apache.coyote.ajp.AjpNio2Protocol'
httpPort = 8088
}
and produces the output in Win10:
>gradlew.bat tomcatRun
> Configure project :
> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :tomcatRun
at this point it hangs for again for around 3 mins with CPU-load below 18% and then continues:
LOG .......
LOG 2020-04-24 12:45:10,971 [Execution worker for ':'] INFO : - ActiveMq URL tcp://localhost:61620
Started Tomcat Server
The Server is running at http://localhost:8088/racy10
<=========----> 75% EXECUTING [4m 2s]
So for no reason (from my POV) the gradle excecution hangs for 3 mins either after or before certain tasks.
Any hints and ideas are welcome!
TIA
Check the permissions of %userprofile%\.gradle directory, which is a common culprit. On Windows 10 this might be affected by Windows Defender, but this should only slow down a little. Testing how it behaves when running it from directly the command-line suggested, because this would help to narrow the down root cause. Instead using an Exec task might also be an option, which would provide full control over the CLI; for example.
Related
I am currently working on Hyperskill (JetBrains academy) on Java Backend Developer track. Every project that I try to check from the Intellij Idea IDE gives me this error:
Failed to launch checking
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':Simple_Search_Engine-task:compileTestJava'.
Could not resolve all files for configuration ':Simple_Search_Engine-task:testCompileClasspath'.
Could not find com.github.hyperskill:hs-test:release-SNAPSHOT.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/github/hyperskill/hs-test/release-SNAPSHOT/maven-metadata.xml
- https://repo.maven.apache.org/maven2/com/github/hyperskill/hs-test/release-SNAPSHOT/hs-test-release-SNAPSHOT.pom
- https://jitpack.io/com/github/hyperskill/hs-test/release-SNAPSHOT/maven-metadata.xml
- https://jitpack.io/com/github/hyperskill/hs-test/release-SNAPSHOT/hs-test-release-v8-g6845035-132.pom
Required by:
project :Simple_Search_Engine-task
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 3s
Task :Simple_Search_Engine-task:compileJava UP-TO-DATE
Task :Simple_Search_Engine-task:processResources NO-SOURCE
Task :Simple_Search_Engine-task:classes UP-TO-DATE
Task :util:compileJava NO-SOURCE
Task :util:processResources NO-SOURCE
Task :util:classes UP-TO-DATE
Task :util:compileTestJava NO-SOURCE
Task :util:processTestResources NO-SOURCE
Task :util:testClasses UP-TO-DATE
Task :Simple_Search_Engine-task:compileTestJava FAILED
2 actionable tasks: 1 executed, 1 up-to-date
My project: https://drive.google.com/drive/folders/1xEV47YXdkVRUfB0JPSEkmcPtBbb5rbvJ?usp=sharing
Project from hyperskill: https://hyperskill.org/projects/66?track=12
I tried reinstalling the IDE or changing the project that I am working but the same errors. When I am uploading the solve directly on hyperskill website it works perfectly fine.
Here is also a video if it is more helpful: https://youtu.be/nvrpHuVq44A
Please help me! :D
Go to the build.gradle file for this project and replace the following line:
'com.github.hyperskill:hs-test:release-SNAPSHOT'
With
'com.github.hyperskill:hs-test:master-SNAPSHOT'
It seems that the release branch has an error, so change it to master.
Then, open up IntelliJ and restart Gradle.
Could you please select JDK 17 as Gradle JVM in Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle?
After that, please ensure that JDK 17 is selected as Project SDK in File | Project Structure.
I have a Gradle project being run from the latest version of IntelliJ IDEA (2021.1.1 Ultimate Edition). The project has a Java class with a main method that outputs its results to the console.
When I run this main method from IntelliJ IDEA, outputs the results of the program in the "Run" tab. However, it also outputs the Gradle build output as well. This is not desirable to me, since it makes the program output harder to visually distinguish, plus I have to carefully select just the program output, and can't just copy/paste the full output (click, ⌘A, ⌘C, click, ⌘V).
build.gradle
plugins {
id 'java'
}
Main.java
package com.example;
public class Main {
public static void main(String[] args) {
System.out.println("Program output line 1");
System.out.println("Program output line 2");
System.out.println("Program output line 3");
}
}
output
1:20:08 PM: Executing task 'Main.main()'...
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :Main.main()
Program output line 1
Program output line 2
Program output line 3
BUILD SUCCESSFUL in 508ms
2 actionable tasks: 2 executed
1:20:09 PM: Task execution finished 'Main.main()'.
Aside
Similar behavior occurs if I switch the project settings to build and run using IntelliJ IDEA rather than Gradle, in that it outputs the Java command and a "process finished" message. Even if I wanted to switch to running in this manner (which I don't for this project), I still run into a variant of this issue.
/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=61588:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/Example/GradleMainOutput/out/production/classes com.example.Main
Program output line 1
Program output line 2
Program output line 3
Process finished with exit code 0
That all being said, is there a way to output only the program output in an IntelliJ IDEA Gradle project, and not the build output?
There is no way to hide Gradle build output when running in this mode.
The only way is to disable Gradle run delegation so that app is started directly by IntelliJ IDEA.
Hiding the command line and the exit code is also not possible.
You can only fold it.
Old question, but for anybody still interested to just get the output of the script, you can use the --quiet flag (https://docs.gradle.org/current/userguide/logging.html)
So having this in the build.gradle :
task(run, dependsOn: 'classes', type: JavaExec) {
main = 'com.multimodule.module.MainClass'
classpath = sourceSets.main.runtimeClasspath
}
and execturing the task:
./gradlew multimodule:module:run --quiet
you'll get just the output (.e.g any System.out.println you added on the main)
The --quiet flag helps, but it is not enough. For me the following flags combination works:
gradle --console-plain --quiet ...
I am currently making a discord bot using Gradle and JDA in Intellij. However, when I tried to run the Gradle - It has been 10 minutes and still going of running the Gradle and it stuck. I tried to clear the cache, close and open the project, and re-build the gradle; I am still stuck at this position
12:11:56 PM: Executing task 'run --stacktrace'...
Starting Gradle Daemon...
Gradle Daemon started in 3 s 230 ms
> Task :compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :processResources
> Task :classes
> Task :run
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging.
Started nijibase with version 1.9.17
STARTING SHARD 0
Where did I go wrong? I don't know what else should I put since the stacktrace hasn't showed me where did I go wrong
I'm in the process of setting up a new GitLab CI pipeline for a project.
As a start, my goal is to create a basic pipeline that builds, tests and analyzes the project (3 simple stages).
My problem is that, that my second stage (test) depends on a Gradle task that generates a bit of documentation (we generated on the fly documentation based on tests). Said task invokes the main of a utility to generate a simple piece of documentation.
While all tasks work fine when I run them under a Windows host, doing the same on GitLab's CI using an Alpine Linux based image fails with the following error:
> Task :compileTestJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test
> Task :generatePermissionsDocument FAILED
Error: Could not find or load main class
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generatePermissionsDocument'.
> Process 'command '/opt/java/openjdk/bin/java'' finished with non-zero exit value 1
I have tried enabling Gradle stacktraces but I did not manage to get any good information out of them. For the most part both my build script and the GitLab CI script look OK (included below for reference):
image: adoptopenjdk/openjdk8:jdk8u222-b10-alpine
include:
- project: "devops/ci-templates"
ref: "master"
file: "sonar/sonar-gradle.yml"
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- apk add --no-cache tzdata
- cp /usr/share/zoneinfo/America/New_York /etc/localtime
- echo "America/New_York" > /etc/timezone
stages:
- build
- test
- analysis
build:
stage: build
script: ./gradlew --build-cache clean assemble -PMARKETING_SKIP_INT_TESTS
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- build
- .gradle
- src/main/java/fts/marketing/util/Version.java
retry: 2
only:
- merge_requests
- master
- /^support\/\d+[.]\d+$/
- tags
except:
- api
test:
stage: test
script: ./gradlew test -PMARKETING_SKIP_INT_TESTS --stacktrace
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
- src/main/java/fts/marketing/util/Version.java
only:
- merge_requests
- master
- /^support\/\d+[.]\d+$/
- tags
except:
- api
Initially I though that the this would be a caching or permission related problem, but I checked both the integrity or the cache produced by the build task as well as the permissions of the generated folder and everything looks fine.
For reference the task I'm trying to invoke is this one:
task generatePermissionsDocument(type: JavaExec, group: 'application') {
description = 'Will generate API Permissions adoc'
main = 'fts.marketing.tools.GeneratePermissionsDocument'
classpath = sourceSets.main.runtimeClasspath
//jvmArgs = applicationDefaultJvmArgs
workingDir = generatedDocumentation
}
Can anyone shed some light as to why this is failing and what must be done to resolve it?
I managed to find out the root cases of this. I was doing some conditional setting of the application's default JVM args which apparently was wrong. Said process was including a trailing ',' in the args passed in by Gradle to the JVM.
For some reason this was not well liked when running from a Unix like environment, whereas it was working fine on Windows hosts. I re-worked the conditional part of the arg setting and everything worked like a charm.
I tried to follow the instructions in https://github.com/cloudfoundry/uaa, namely cloning the github repository and then executing the gradlew run command. I am running this on a Windows 10 system that has Java 1.8 installed. However, I run into the following error at around 97% of the execution of gradlew run.
org.codehaus.cargo.container.ContainerException: Deployable [http://localhost:8080/cargocpc/index.html] failed to finish deploying within the timeout period [120000]. The Deployable state is thus unknown.
:cargoRunLocal FAILED
:cargoRunLocal took 164921ms
FAILURE: Build failed with an exception.
I am new to the Java ecosystem and I am not sure what the issue is. I tried looking up for increasing the timeout as seems to be the initial observation from the issue. I am not sure where to do this. I do not know if the issue is from a completely different reason.
Any suggestions would help
Looks like process is getting timed out before it deploys the application, try increasing the timeout period in build.gradle file.
Open build.gradle in the root of the uaa
Search for below content:
cargo {
containerId = tomcatContainerId
port = 8080
...
Increase the timeout by adding timeout = 180000
cargo {
containerId = tomcatContainerId
port = 8080
timeout = 180000
...