Gradle task failing on GitLab CI main method not found - java

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.

Related

React native gradle build failed

I cloned a react-native project from github and below are the steps that I followed in order to make it work on my local ubuntu 20.04 machine:
(The project was expo managed earlier, but now it is ejected because there are android and ios folders)
created my local feature branch -> git checkout -b feature
installed all the packages in package.json -> yarn install
ran npx react-native run-android to run the app on android emulator
1st Encountered error:-
Could not write standard input to Gradle build daemon.
java.io.IOException: Stream closed
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
In order to solve this issue, I used this https://stackoverflow.com/a/69630720/11685381 answer and removed -XX:MaxPermSize=512m from my gradle.properties
2nd Encountered error:-
Again used npx react-native run-android and ran into another build error:-
* What went wrong:
Could not open settings generic class cache for settings file '/home/user/project/android/settings.gradle' (/home/user/.gradle/caches/6.9/scripts/5bii70nilhgbvb8zyo7v963b7).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
To fix this, I used this solution: https://www.codegrepper.com/code-examples/whatever/BUG!+exception+in+phase+'semantic+analysis'+in+source+unit+'_BuildScript_'+Unsupported+class+file+major+version+61
3rd Encountered error:-
Again ran npx react-native run-android and ran into these 2 build error this time:
1: Task failed with an exception.
-----------
* Where:
Build file '/home/user/project/node_modules/expo-gl-cpp/android/build.gradle' line: 307
* What went wrong:
Default side-by-side NDK installation is not found.
Set $ANDROID_NDK_HOME environment variable correctly or setup ndk.dir in local.properties.
> NDK is not installed
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':expo'.
> compileSdkVersion is not specified. Please add it to build.gradle
To solve the 1st issue i.e. NDK is not installed (it is installed though), I created a local.properties inside project/android directory and pasted the following path:
sdk.dir=/home/user/Android/Sdk
ndk.dir=/home/user/Android/Sdk/ndk/24.0.8215888
4th Encountered error:-
> Task :app:generatePackageList FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
* Where:
Script '/home/user/project/node_modules/#react-native-community/cli-platform-android/native_modules.gradle' line: 131
* What went wrong:
Execution failed for task ':app:generatePackageList'.
> argument type mismatch
To solve this, I tried this solution: https://stackoverflow.com/a/68180959/11685381 but this again downloaded the gradle 6.9 which I had earlier also, and again to the 2nd Encountered error
I've been doing this since 2 days, can someone please help me out here what am I doing wrong?
Try updating build.grade from
classpath("com.android.tools.build:gradle:3.5.3")
To
classpath("com.android.tools.build:gradle:3.5.4")
It's just an example. try to update Gradle.

run gradle take a long time and still going

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

Sonarcloud is not authorized using Travis CI and Maven

I have an experimental project on my Github used for the practising the CI service integrations. I struggle with using Sonarcloud.
I have followed both Tavis CI + Sonarcloud tutorial and Maven example. Mz first confusion starts with the token and properties file whereas the first source suggests creating sonar-project.properties file and the Maven example source does not have any. Here where the documentation is very unclear.
I ignored the properties file and I have done the following steps:
Generated token on sonarcloud.io for my project: e53.....239
Encrypted token on travis-encrypt.github.io since it's the most comfortable way for a Windows user. The 2 following inputs resulted in g3s.....+Q=:
NicharNET/Gistintex
SONAR_TOKEN="e53...239" - I tried both to wrap between quotation marks and without.
Added to Settings -> Environment variable key SONAR_TOKEN with the value of the generated Sonarcloud token e53...239.
Completed travis.yml with the secure token:
language: java
sudo: false
jdk: oraclejdk8
addons:
sonarcloud:
organization: "nicharnet-github"
token:
secure: "g3sLTdS597mklh1I9HgXr71NRCiOk2n9I41PL2wklnAidwibfocyEcWvSQxjmbhNTjdrcW0cAfzh73Ago8hwfdloraryDY9Ng9L1runxayShtPOqZMPI6nz8zUwLaDfqJVwXWv6A3xICOMFl0UhvF351GPErHhrUO7YIa8el3kESeotYy7kkTzeQ7BA239y7EVFw8H4OCW2gjP2G/InxKnlXfNjgQA3GsnZdJ3uWO3No5kwt5ybfuCCV42cp/UczLIzNbo0RW9Z9jBl5IFMzJaUQUfWV3Pp5QEPmpB7Anr/4W1EtjJPjpSIC/+jBmbrkvC/CSzzTPjaH9LzEQ5m4F5JpRw01blqgKH/153qfs1jRgZK6WVRuhe7yAATHCO/IM0DM+kC0mUJTcXKyv9pRm93E4wp+KzdHYy0LdA83wFgMmvlB8pcm20ImAe7B2SBFx5TGtETa6ea6k2BS+DfBXe6sLBnrl1zZB8nxCDnYiwT1BJFxizgv3EJ6Krjd3cSSxr6PGnXDD/yTeFNJarpMbA+wR6AQetJ89LiDBXYiw6GPgWk/A4vUDIsIaXGqCpydeZHkr2ufS1Ap4yYS0Um2GeDeQXTsBTSCg7BViFgduUI1NPYT1avKg7b64nsdpdjBVofOvzJsgiT66WlaJmt23BUCJsnmXwwEcW1387b4G+Q="
script:
- mvn clean install org.jacoco:jacoco-maven-plugin:prepare-agent sonar:sonar
Committed and pushed changes into the repository and Travis CI started to work and resulted in:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project gistintex: Not authorized. Please check the properties sonar.login and sonar.password.
The error could be found on my Travis CI build. What do I do wrong?
I have skimmed through Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password SO question and Travis CI Sonarqube analysis article, which unfortunately didn't help me though. My GitHub project source.
I have tried to add these plugins to pom.xml and run the analysis locally:
org.codehaus.mojo: sonar-maven-plugin: 5.1
org.sonarsource.scanner.maven: sonar-maven-plugin: 3.4.1.1168
Running this on my machine resulted in the correct Sonarcloud analysis:
mvn sonar:sonar \
-Dsonar.organization=nicharnet-github \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=e53.....239
However, my goal is to run the analysis after every committed version using Travis CI. I am sure I have done wrong the key encryption but I can't figure what exactly.
The key encryption problem usually happens when you execute the generation without the login command against travis.com instead of travis.org
In order to run on every commit you could connect your repo with SonarCloud Scan, generate a secret in your sonarcloud.io project page and there you will find instructions to modify your .travis.yml
if you use travis.org
travis encrypt <YOUR_SONAR_SECRET>
if you use travis.com
travis login --pro
then generate your token like this:
travis encrypt --pro <YOUR_SONAR_SECRET>
finally you need to add your pipeline instruction to your .travis.yml file
Check in your Travis CI repo settings when it should be triggered
here some related links:
Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password
https://docs.travis-ci.com/user/encryption-keys/#usage
https://github.com/marketplace/actions/sonarcloud-scan
https://sonarcloud.io/documentation/integrations/github/

Gradle build failed on Travis CI

I used filteringCharset = 'UTF-8' because of encoding problems in ProcessResources in build.gradle. This build succeeded on my desktop, but failed on Travis CI. I guess this is the problem with Travis CI's Gradle. So I tried to update the version but could not find any information. Is this the problem with the Gradle version? If yes, what can I do?
Travis build error:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/travis/build/EntryPointKR/K-Security/build.gradle' line: 43
* What went wrong:
A problem occurred evaluating root project 'K-Security'.
> No such property: filteringCharset for class: org.gradle.language.jvm.tasks.ProcessResources_Decorated
Full travis build log: https://travis-ci.org/EntryPointKR/K-Security/builds/201771722
.travis.yml:
language: java
sudo: false
jdk:
- oraclejdk8
addons:
apt:
packages:
- oracle-java8-installer
Problem code in build.gradle
processResources {
filteringCharset = 'UTF-8' // Here
filter ReplaceTokens, tokens: [
"version" : project.version,
"pluginName": rootProject.name,
"mainClass" : "cloud.swiftnode.ksecurity.KSecurity",
"author" : "EntryPoint"
]
}
This is very likely due to a mismatch between your gradle version and the gradle version installed in the java image. It was introduced in Gradle 2.14. The easiest fix is to use gradle wrapper to enforce the same version in both environments.
Simply add the wrapper task:
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}
It should be possible to run gradle wrapper in before_install, or simply bundle the gradle-wrapper jar with your project. Travis CI will detect gradle wrapper and use gradlew instead of gradle.
If you are using Windows on your local machine, make sure you commit the gradlew script with executable flag.

jenkins finished success while the make command failure

I used jenkins to build android image nightly, and then found even the make and cp command failure,the jenkins still finished success.
The last build setup is to copy log file to job directory, so maybe it succeed,and then jenkins finished SUCCESS.
And the Text-finder plugin can only set build unstable not failure, so how to make the build failure when make fails.
The log is like this:
make: \*** No rule to make target \`device/vendor/product/google_frameworks/Google_Play.apk', needed by `out/target/product/device/system/app/Google_Play.apk'. Stop.
make: *** Waiting for unfinished jobs....
target R.java/Manifest.java: FileBrowser(out/target/common/obj/APPS/FileBrowser_intermediates/src/R.stamp)
Warning: AndroidManifest.xml already defines versionCode (in http://schemas.android.com/apk/res/android); using existing value in manifest. untranslatable but exists in locale 'zh_CN'
aapt: warning: string 'pref_development_uastring' has no default translation in packages/apps/Browser/res; found: zh_CN zh_TW
Note: Recompile with -Xlint:unchecked for details.
======================>End<=======================
cp: cannot stat `/home/jenkins/job_name/source/out/target/product/device/package.img': No such file or directory
Extended Email Publisher is currently disabled in project settings
Finished: SUCCESS
The Jenkins job is marked as successfull if the last command of the script has succeed.
A simple workaround is to specify set -e at the begginning of your bash script.
-e Exit immediately if a command exits with a non-zero status.
You can also specify a trap: trap 'exit 1' ERR, to stop the script if an error occurs.

Categories