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.
Related
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.
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.
New to Gradle. I Apologize if this is a bad question.
I've been trying to start a plain Java8 Gradle project. Everything was great until I tried to add Lombok to my project.
My Intellij IDE has all the settings required for Lombok.
Lombok plugin installed and activated
Annotation processor is on
The IDE is handling the annotations perfectly. No errors showing, and the boilerplate is shown in the code structure.
However, when I try to build the project or run the main method using Intellij, the compiler complains that the boilerplate Lombok is supposed to generate doesn't exist.
Environment
186590cf4989:JokerJava$ gradlew --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.5 (Oracle Corporation 11.0.5+10-LTS)
OS: Mac OS X 10.14.6 x86_64
Some error message below:
8:23:21 PM: Executing task 'build'...
> Task :generateLombokConfig UP-TO-DATE
> Task :compileJava FAILED
2 actionable tasks: 1 executed, 1 up-to-date
warning: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.gradle.api.internal.tasks.compile.processing.IncrementalProcessingEnvironment
Lombok supports: sun/apple javac 1.6, ECJ
workspace/tank/JokerJava/src/main/java/tictactoe/game/gui/TicTacToeButton.java:11: error: variable index not initialized in the default constructor
private final int index;
^
workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:42: error: constructor TicTacToeButton in class TicTacToeButton cannot be applied to given types;
buttons[i] = new TicTacToeButton(i);
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:70: error: cannot find symbol
int index = buttonClicked.getIndex();
^
symbol: method getIndex()
location: variable buttonClicked of type TicTacToeButton
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:86: error: cannot find symbol
update(opponentAction.getPlayer(), opponentAction.getIndex());
^
symbol: method getPlayer()
location: variable opponentAction of type UserAction
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:86: error: cannot find symbol
update(opponentAction.getPlayer(), opponentAction.getIndex());
^
symbol: method getIndex()
location: variable opponentAction of type UserAction
Note: /workspace/tank/JokerJava/src/main/java/Client.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors
1 warning
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* 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 1s
8:23:22 PM: Task execution finished 'build'.
See below for my build.gradle config
plugins {
id 'java'
id "io.freefair.lombok" version "5.0.0-rc2"
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Even if you don't want to use spring, head over to the spring Initializer at https://start.spring.io/ and choose Gradle and add the Lombok dependency. It'll create a build.gradle for you with Lombok in the appropriate configurations (including annotationProcessor)
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.
I just downloaded the latest version, SonarQube 4.3,
then try build a java-8 project with:
mvn clean install
mvn sonar:sonar
That gives me the Exception below.
Googling, I got the impression this is an earlier issue that should have been fixed... ?
http://sonarqube.15.x6.nabble.com/Sonar-analyze-Java-1-8-project-Failure-td5023663.html
http://jira.codehaus.org/browse/SONARJAVA-482
Does SonarQube 4.3 support java-8?
Or any clue, what is the problem?
-------------------------------------------------------
T E S T S
-------------------------------------------------------
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
at org.jacoco.agent.rt.internal_6effb9e.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_6effb9e.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.lang.Class.getField(Class.java:1690)
at org.jacoco.agent.rt.internal_6effb9e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
I got the missing info from the SonarQube mailing-list...
To summarize:
To get Java8 maven-build working on SonarQube-4.3:
Install sonarqube-4.3, and start the server.
Login to the web-gui => Settings => Update Center => Plugins Updates => Java => Click "Upgrade to 2.2.1"
Wait a minute or so for the upgrade to complete... then shutdown+restart sonarqube.
Go back into the Upgrade Center and verify you have plugin: Java 2.2.1
To get code-coverage in Sonar, you now need to build with these commands:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install
mvn sonar:sonar
Reference: http://docs.codehaus.org/display/SONAR/JaCoCo+Plugin
That's it.
Here with java 11 I had this problem and I fix adding this in my gradle properties:
jacoco {
toolVersion = "0.8.4"
}
If you are running jacoco with gradle them update the jacoco to latest version.
I was also facing the similar issues and it got fixed after below changes
Java 11 and Gradle
jacoco {
toolVersion = "0.8.4"
}
I was getting the same error when mvn building a Java 1.7 project using JDK 1.8. The solution was simple: I changed the jacoco plugin version to a newer version:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
(The project was using version 0.6.3.201306030806 before.)
SonarQube 4.3 embeds Java plugin 2.1 whereas http://jira.codehaus.org/browse/SONARJAVA-482 has been fixed in version 2.2. So by upgrading the Java plugin to version 2.2.1, this should fix your issue.
Setting $JAVA_HOME resolved the problem for me.
We had the same issue. What we did was re-install sonarqube 4.3 with Java 8 already installed. Then run analysis against sonar. If you already have sonar/java 7 installed previously and have ran analysis against it, sonar seems to install some plugins which causes these failures. If you re-install just sonar and java 8 (dont remove mysql database etc... so history is intact) - re run your analysis it seems to solve the problem with the plugins.
I have done the following changes to come out from the problem.I have used the two steps for it , first one is that update the jacoco in latest version along with its toolVersion , please check it once below
classpath "com.dicedmelon.gradle:jacoco-android:0.1.4"
And toolVersion is as follow
jacoco {
toolVersion = "0.8.4"
}
Please refer the link for more info Click here
And now check the second step for it in which we use the excludes = ['jdk.internal.*'] inside the testOption like below
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
excludes = ['jdk.internal.*']
}
}
}
For more info in it, please check the link Click here