Recently I downloaded Spring Boot 3 to test the embedded GraalVM. I run the `./gradlew native compile command the result is:
$ ./gradlew nativeCompile
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':nativeCompile'.
> Invalid GAV coordinates: groovy:it_groovy_comparre: (expected format: groupId:artifactId: version)
....
BUILD FAILED in 752ms
What is my problem with dependencies? When I run that command in debug mode there is nothing new except this error.
NOTE:
my $JAVA_HOME variable value is: /home/<my username>/.jdks/graalvm-ce-java17-22.3.0/, which point to a Graalvm java
my build automation tool is Gradle.
When I tested the command in groovy the result was the same
I found the solution.
Firstly I added a version to my build.gradle file like this :
plugins {
// ...
}
group = 'groovy'
version = '1' // <-------------- HERE
sourceCompatibility = '17'
configurations {
//...
}
Just before executing the command ./gradlew nativeCompile, I ran the following two commands :
$ ./gradlew processAot
...
$ ./gradlew processTestAot
...
After that, everything works fine.
Related
I want to using GraalVM in my Spring Boot 2.3.10.RELEASE project because it can decrease the memory usage of JVM(Now I am using JDK 11), so I add the dependencies:
api "org.springframework.experimental:spring-native:0.10.2"
add the gradle plugin:
apply plugin: "com.github.ayltai.spring-graalvm-native-plugin"
add native build config:
nativeImage {
mainClassName = 'com.dolphin.soa.manage.AppStarter'
traceClassInitialization = true
reportExceptionStackTraces = true
removeUnusedAutoConfig = true
removeYamlSupport = true
removeSpelSupport = true
removeJmxSupport = true
maxHeapSize = '4G'
}
finnaly I am using this Gradle(7.0) command to build a native jar:
./gradlew clean :dolphin-manage:dolphin-manage-service:bootBuildImage -x test
but show this error:
> Configure project :dolphin-acientbay
/Users/dolphin/source/retire
> Configure project :dolphin-post
/Users/dolphin/source/retire
> Configure project :dolphin-template
/Users/dolphin/source/retire
> Task :dolphin-common:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':dolphin-common:compileJava'.
> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module #0x2155f75f) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module #0x2155f75f
* 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 6m 49s
5 actionable tasks: 1 executed, 4 up-to-date
(base)
is it a compatible problem about GraalVM and lombok? is it possible to fix it?
I'm seeing this same type of error running spotless on my Java project. I just reported a bug about this to them: https://github.com/diffplug/spotless/issues/1244
I diagnosed the problem as some kind behavioral change between Java 15 and Java 16. So one thing you can do is revert to an earlier version of Java to see if that makes the issue go away. If it does, you should report a bug similar to what I did to the project with the problem so they can try to fix it.
I have recently upgraded my project from Java 8 to Java 11 alongside Gradle 6.5.
However, when I run the command ./gradlew pitest I receive the following error:
Execution failed for task ':pitest'.
> The value for task ':pitest' property 'mainClass' is final and cannot be changed any further.
Here is my pitest set-up in my build.gradle:
pitest {
pitestVersion = '1.4.3'
targetClasses = ['com.myproject.*']
excludedClasses = [
'com.myproject.configuration.*',
'com.myproject.controller.*',
]
threads = 10
enableDefaultIncrementalAnalysis = true
historyInputLocation = ['build/reports/pitest/fastermutationtesting']
historyOutputLocation = ['build/reports/pitest/fastermutationtestingoutput']
outputFormats = ['XML', 'HTML']
timestampedReports = true
mutationThreshold = 90
}
and here are my pitest related dependencies:
Plugins{
id "info.solidsoft.pitest" version '1.3.0'
}
testCompile 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.3.0'
I am not sure where this mainClass property is coming from and have not found any related answers or documentation on this issue.
I was able to resolve my issue by upgrading the dependency versions to:
id "info.solidsoft.pitest" version '1.5.1'
and
testCompile 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.4.0'
after increasing the dependency versions, the command ./gradlew pitest was working as normal and the pitests were running fine.
Gradle throws a NoClassDefFoundError when trying to execute a grgit task.
Start of build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'org.ajoberstar:gradle-git:1.2.0'
}
}
apply plugin: 'com.android.application'
//
//
import org.ajoberstar.grgit.*
task clone << {
File dir = new File('contrib/otherstuff')
if(!dir.exists()) {
def grgit = Grgit.clone(dir: dir, uri: 'https://github.com/someguy/otherstuff.git')
}
// TODO else (pull)
}
project.afterEvaluate {
preBuild.dependsOn clone
}
// rest omitted
Output:
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:src:myproject:clone FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '/home/me/src/myproject/build.gradle' line: 20
* What went wrong:
Execution failed for task ':src:myproject:clone'.
> java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 16.937 secs
Line 20 is the call to Grgit.clone().
Do I need to add groovy as a build dependency (which the error message seems to indicate)? How and where would I add it?
EDIT: gradle version is 1.10, if it matters.
As #user149408 pointed out the Gradle version (v1.10 vs v2.10) mismatch, I dug a little bit further:
gradle-git-plugin commit for v0.7.0 specifies the Gradle version used (v1.11), so the build with v1.10 works fine.
Because the Gradle plugin always built with compile localGroovy() and compile gradleApi() which comes from Gradle, then if it builds with Gradle 2.x, it would incur the Groovy mismatch error.
What went wrong: Execution failed for task ':src:myproject:clone'.
java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling
In fact, the combo of Gradle v2.10 and gradle-git v1.2.0 just works fine.
Some sample build.gradle similar structure as in the question.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.2.0'
}
}
import org.ajoberstar.grgit.*
task clone << {
File dir = new File('contrib/gs-spring-boot')
if(!dir.exists()) {
def grgit = Grgit.clone(dir: dir, uri: 'https://github.com/chenrui333/gs-spring-boot.git')
}
// TODO else (pull)
}
./gradlew clone would give you:
$ ls contrib/gs-spring-boot/
CONTRIBUTING.adoc LICENSE.code.txt LICENSE.writing.txt README.adoc complete initial test
Hope it helps!
I’ve managed to solve it.
grgit-1.2.0 appears to depend on groovy. Adding a classpath entry for groovy in the buildscript/dependencies block resulted in a different error:
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:src:myproject:clone FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '/home/me/src/myproject/build.gradle' line: 23
* What went wrong:
Execution failed for task ':src:myproject:clone'.
> java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for org.ajoberstar.grgit.auth.AuthConfig$Option do not match. Expected -1 but got 2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 12.295 secs
Further research revealed that this might stem from a version incompatibility (as I’m stuck with Gradle 1.10 for other reasons).
Eventually I solved it by going back to grgit-0.7.0. Now my git task works and the repo gets cloned.
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.
In all of my projects, I use gradle and specify the following:
sourceCompatibility = "1.7"; // for example
targetCompatibility = "1.7"; // defaults to sourceCompatibility
Now, I have three different versions of the JDK installed, from 1.6 to 1.8. In order to switch from one version to another, I source shell files to change PATH, JAVA_HOME and even JDK_HOME.
By accident it can happen that I use the wrong JDK version and I don't want that... Is there a possibility to check that the compiler version is equal to targetCompatibility before attempting any compilation task?
Answer to self, and thanks to #JBNizet for providing the initial solution...
The solution is indeed to use JavaVersion, and it happens that both sourceCompatibility and targetCompatibility accept a JavaVersion as an argument...
Therefore the build file has become this:
def javaVersion = JavaVersion.VERSION_1_7;
sourceCompatibility = javaVersion;
targetCompatibility = javaVersion; // defaults to sourceCompatibility
And then the task:
task enforceVersion << {
def foundVersion = JavaVersion.current();
if (foundVersion != javaVersion)
throw new IllegalStateException("Wrong Java version; required is "
+ javaVersion + ", but found " + foundVersion);
}
compileJava.dependsOn(enforceVersion);
And it works:
$ ./gradlew clean compileJava
:clean UP-TO-DATE
:enforceVersion FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '/home/fge/src/perso/grappa-tracer-backport/build.gradle' line: 55
* What went wrong:
Execution failed for task ':enforceVersion'.
> Wrong Java version; required is 1.7, but found 1.8
I use the following:
task checkJavaVersion << {
if (!JavaVersion.current().isJava6()) {
String message = "ERROR: Java 1.6 required but " +
JavaVersion.current() +
" found. Change your JAVA_HOME environment variable.";
throw new IllegalStateException(message);
}
}
compileJava.dependsOn checkJavaVersion
If you want the version to be checked for all tasks, you can add an assertion in build.gradle to enforce it:
assert JavaVersion.current().isJava9Compatible(): "Java 9 or newer is required"
With Gradle 5.4.1, the failure looks like this:
$ ./gradlew --quiet build
FAILURE: Build failed with an exception.
* Where:
Build file '/home/codehearts/build.gradle' line: 15
* What went wrong:
A problem occurred evaluating root project 'Codehearts'.
> Java 9 or newer is required. Expression: org.gradle.api.JavaVersion.current().isJava9Compatible()
* 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
You can also check exact versions if needed:
assert JavaVersion.current().isJava9(): "Java 9 is required"