Dependency resolution fails on Gradle 5.1 - java

I am facing an issue with my gradle project during migration to Gradle 5.1 from Gradle 4.10.2 :
Issue :
./gradlew clean build
> Task :subprojects:lib-abc-admin:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':subprojects:lib-abc-admin:compileJava'.
> Could not resolve all files for configuration ':subprojects:lib-abc-admin:compileClasspath'.
> Could not find org.glassfish.jersey:jersey-bom:.
Required by:
project :subprojects:lib-abc-admin
BUILD FAILED in 2s
In previous version Gradle 4.10.2, this error was getting circumvented by the following switch:
enableFeaturePreview("IMPROVED_POM_SUPPORT")
But in gradle 5 this switch has been deprecated, seems like this doesn't work anymore and I am getting the errors.
Any alternatives / suggestions / solutions ?
Toolchain Details :
------------------------------------------------------------
Gradle 5.1
------------------------------------------------------------
Kotlin DSL: 1.1.0
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.1 (Oracle Corporation 11.0.1+13-LTS)
OS: Linux 4.19.8-200.fc28.x86_64 amd64

From gradle issue:
Different approaches were tried for supporting BOMs.
In Gradle 5.0, through feedback from the community (see #4422), we ended up deciding on an explicit notation to import a BOM.
So you will need to update dependencies on modules that are BOMs to that notation.
See documentation for details.
And since the IMPROVED_POM_SUPPORT feature is now enabled by default, you can remove the enableFeaturePreview("IMPROVED_POM_SUPPORT") line from your settings.gradle(.kts)

Related

GraalVM native image build `nativeCompile` task fails on Gradle after migrating from Java11 to Java17

In summary, after migrating Gradle properties (source/target) and native GraalVM image from Java11 to Java17, the build task fails on Gradle.
This is a micronaut Java service and without giving away any proprietary codebase details, I'm sharing the following portion of my Gradle's output of the failed 'nativeCompile' task:
[1/7] Initializing... (8.0s # 0.36GB)
Version info: 'GraalVM 22.3.1 Java 17 CE'
Java version info: '17.0.6+10-jvmci-22.3-b13'
C compiler: gcc (redhat, aarch64, 8.5.0)
Garbage collector: Serial GC
6 user-specific feature(s)
- com.oracle.svm.thirdparty.gson.GsonFeature
- io.micronaut.buffer.netty.NettyFeature
- io.micronaut.configuration.kafka.graal.ChecksumFeature
- io.micronaut.grpc.server.graalvm.HttpNettyFeature
- io.micronaut.http.netty.graal.HttpNettyFeature
- io.micronaut.jackson.JacksonDatabindFeature
Fatal error: ------------------------------------------------------------------------------------------------------------------------
0.5s (5.9% of total time) in 12 GCs | Peak RSS: 1.26GB | CPU load: 2.25
========================================================================================================================
java.lang.IllegalAccessError: class io.micronaut.grpc.server.graalvm.HttpNettyFeature (in unnamed module #0x128ca7af) cannot access class com.oracle.svm.core.jdk.SystemPropertiesSupport (in module org.graalvm.nativeimage.builder) because module org.graalvm.nativeimage.builder does not export com.oracle.svm.core.jdk to unnamed module #0x128ca7af
at io.micronaut.grpc.server.graalvm.HttpNettyFeature.beforeAnalysis(HttpNettyFeature.java:84)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:736)
Failed generating 'application' after 8.2s.
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:85)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:736)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Error: Image build request failed with exit status 1
> Task :nativeCompile FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nativeCompile'.
> Process 'command '/opt/graalvm-ce-java17-22.3.1/bin/native-image'' finished with non-zero exit value 1
I have no experience with GraalVM (this is legacy, and am running the nativeCompile inside a container that was created like this:
docker run -it --entrypoint /bin/bash \
--mount type=bind,source=<path to service source code>,target=/app \
--mount type=bind,source=<path to home>.gradle,target=/root/.gradle \
ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.1
On this container, the env details are as follows:
bash-4.4# ./gradlew --version
------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------
Build time: 2022-11-25 13:35:10 UTC
Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8
Kotlin: 1.7.10
Groovy: 3.0.13
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.6 (GraalVM Community 17.0.6+10-jvmci-22.3-b13)
OS: Linux 5.15.49-linuxkit aarch64
I have little idea of what to pursue here, would like to know if there is a native dependency that is outdated. I know I haven't posted my build.gradle nut hopefully someone can give me some pointers so far.
Fixed it. Seems like GraalVM publishes updates that must be used in lockstep with older minor versions. I guess it's a way to keep native classes compatible.
In my case, the older native image, gradle and code base setup was using ol8-java11-22.1.0 and I updated it all to ol8-java17-23.2.1, the latest available. This broke the build.
However, GraalVM also publishes ol8-java17-22.1.0 which matches the older minor versions. This worked without any issues, built successfully.

Adding mockito-inline dependecy in pom.xml causing Mockmaker issue [duplicate]

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration#4158debd
Caused by: java.lang.reflect.InvocationTargetException
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker.
It appears as if your JDK does not supply a working agent attachment mechanism.
Java : 16
JVM vendor name : Oracle Corporation
JVM vendor version : 16.0.2+7-67
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 16.0.2+7-67
JVM info : mixed mode, sharing
OS name : Mac OS X
OS version : 11.5
Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process
Getting the above error on Maven 3.8.1 and JDK16.02 with Mockito 3.7.7, on a fresh setup and cannot figure out why. I have tried every Mockito version from 3.7 all the way to 3.11 to no avail.
These configurations however works on an older setup based on JDK15 on Windows 10 Pro.
Mockito core depends on a library called byte-buddy and this problem is mostly occurred when mockito doesn’t find a matching byte buddy jar version.
Find out the mockito core version your project is using. In eclipse, you can check in project build path by navigating to
Right click on project -> Properties -> Java build path -> Libraries tab
Search maven repository for that version of mockito core.
Look at the Compile Dependencies section. Note down the correct dependent version of byte-buddy and include in the project. If the jar is already included with some other version, override the version with this correct version.
Build the application and run the tests again. Your issue related to MockMaker must be solved by now.
In my case I was running with an old 1.8 JDK. As of this writing with the dependencies below, it has to be Java 11.
testImplementation(platform('org.junit:junit-bom:5.8.2'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '4.2.0'
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '4.2.0'
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.8.2')

libGDX Error FAILURE: Build failed with an exception

This is the error I get from the console of the program and it won't let me even import the gradle to Eclipse
Generating app in C:\Users\mrgnh\Desktop\libGDXstuff
Executing 'C:\Users\mrgnh\Desktop\libGDXstuff/gradlew.bat clean --no-daemon'
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.7.1/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing
FAILURE: Build failed with an exception.
Where:
Settings file 'C:\Users\mrgnh\Desktop\libGDXstuff\settings.gradle'
What went wrong:
Could not compile settings file 'C:\Users\mrgnh\Desktop\libGDXstuff\settings.gradle'.
startup failed:
General error during semantic analysis: Unsupported class file major version 60
It turns out I am blind and that libGDX does not support JDK 16 only 8-15
So when creating the gradle with the JDK 16 gradle System it wasn't working out
Try to change to latest gradle website version of gradle in file: Gradle -> Wrapper -> gradle-wrapper.properties
It helped me.

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.

SonarQube on Java8-project gives jacoco-Exception

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

Categories