grgit NoClassDefFoundError - java

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.

Related

Environment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module

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.

* What went wrong: Task 'bootJar' not found in project ':app-cloud-config-server'. * Try: Run gradlew tasks to get a list of available tasks

This is my first question on stack overflow.
So I am trying to run the build my springboot application app-cloud-config-server on my local system.
I ran this cd /app; ./gradlew app-cloud-config-server:build command on the terminal and got the below error:
What went wrong: Task 'bootJar' not found in project ':app-cloud-config-server'. * Try: Run gradlew tasks to get a list of available tasks. 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.
I checked multiple threads for the solution to this error based on which I tried
Including this in my build.gradle file to find the missing bootJar task
bootJar {
mainClassName = 'foxtrot.infra.applications.cloudconfig.CloudConfigServerApplication'
baseName = 'spring-boot-integration-test'
version = '0.1.0'
}
Couldn't resolve
Applied the below plugins
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
Did gradle clean and followed the same steps
still couldn't resolve the issue.
What am I missing here?

Could not find method outputDir() on cucumber Java source of type org.gradle.api.internal.file.DefaultSourceDirectorySet

I am not able to run the cucumber task for the "com.github.samueltbrown.cucumber" plugin.
I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/freid/app/build.gradle' line: 118
* What went wrong:
A problem occurred evaluating root project 'app'.
> Could not find method outputDir() for arguments [/Users/freid/app/src/cucumber/java] on cucumber Java source of type org.gradle.api.internal.file.DefaultSourceDirectorySet.
* 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 0s
Here is my build.gradle file:
buildscript {
ext {
springBootVersion='2.2.4.RELEASE'
lombokVersion='1.18.4'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'java'
id 'com.github.psxpaul.execfork' version '0.1.8'
id "com.jfrog.artifactory" version "4.7.2"
id "com.github.samueltbrown.cucumber" version "0.9"
}
dependencies {
testCompile 'info.cukes:cucumber-java:1.2.4'
}
sourceSets {
cucumber {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/cucumber/java')
}
resources.srcDir file('src/cucumber/resources')
}
}
cucumber {
formats = ['html:build/reports/html', 'json:build/reports/cucumber.json']
jvmOptions {
environment 'tag', System.getProperty("tag")
environment 'cucumber.local.server', 'localhost'
}
}
Given that the plugin com.github.samueltbrown.cucumber version 0.9 was released in 2015 and you are trying to run with a recent Spring Boot version, I would assume you are using a recent Gradle version as well.
So I believe you are hitting an incompatibility between the plugin and the Gradle version. Most likely an API changed and what the plugin does internally no longer works.
[/Users/freid/app/src/cucumber/java] looks like the toString of a collection of files, while SourceDirectorySet.outputDir only accepts a single File. So my guess is that the API of what returns the value that is used changed from a single file to a file collection at some point.

Dropwizard + Gradle fatJar for project with subprojects pulls in gradle-api-5.4.1.jar deps

I have a Gradle project that as a simple example looks similar to this:
root
|
|build.gradle.kts
|settings.gradle.kts
|config.yaml
|web/
|build.gradle.kts
|src/
|main/
|java....(etc)
The web project is a barebones Dropwizard app that does nothing other than declare a configuration and an application that uses it so that the server can start up.
In my root path, I have defined my subproject (:web in this case) in the settings.gradle.kts file. In my root build.gradle.kts, I have a implementation(project(":web")) dependency declared.
I have a run task and a fatJar task to run/build this app.
val run by tasks.getting(JavaExec::class) {
args("server", "config.yaml")
}
val fatJar = task("fatJar", type = Jar::class) {
manifest {
attributes["Implementation-Title"] = "Some API"
attributes["Main-Class"] = "my.package.web.HelloWorldApplication"
}
from(configurations.runtimeClasspath.get().map({ if (it.isDirectory) it else zipTree(it) }))
with(tasks.jar.get() as CopySpec)
}
tasks {
"build" {
dependsOn(fatJar)
}
}
I can build the fatJar and it contains what appears to be all the classes I expect (dependencies at root, dependencies of web, their transitive dependencies, etc).
However, when I run ./gradlew run I get an error starting the Dropwizard app due to multiple logging bindings found on the class path. Error is below:
./gradlew run
Starting a Gradle Daemon, 1 busy and 1 incompatible and 3 stopped Daemons could not be reused, use --status for details
> Task :run
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/me/.gradle/caches/5.4.1/generated-gradle-jars/gradle-api-5.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/me/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext]
Exception in thread "main" java.lang.IllegalStateException: Unable to acquire the logger context
at io.dropwizard.logging.LoggingUtil.getLoggerContext(LoggingUtil.java:46)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:52)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:41)
at io.dropwizard.Application.bootstrapLogging(Application.java:38)
at io.dropwizard.Application.<init>(Application.java:26)
at my.package.web.HelloWorldApplication.<init>(HelloWorldApplication.java:15)
at my.package.web.HelloWorldApplication.main(HelloWorldApplication.java:17)
> Task :run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* 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 25s
13 actionable tasks: 1 executed, 12 up-to-date
I know I can remove logback from Dropwizard but I'd really rather figure out why gradle-api-5.4.1.jar is being bundled into my application. I can't for the life of me figure it out and don't understand why it would be pulled in.
Any direction would be appreciated.
Thanks
So my mistake in both asking this question and in what I was doing was that I failed to mention or realize that I was applying the kotlin-dsl plugin in my root script on accident. Once I removed this, everything worked as I expected.
You have to add the following in the dependency section of your build.gradle file.
dependencies {
compile('io.dropwizard:dropwizard-core:1.2.2') {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
}

Cannot deploy locally using Cargo plugin for Gradle

I'm having some problem to deploy a Java application using Cargo plugin for Gradle.
I've tried to add commons-discovery and commons-logging as dependencies but it didn't work as well.
:build
:copyWarToTomcat
:removeSymLinks
:removeExplodedWar UP-TO-DATE
:cargoRunLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':cargoRunLocal'.
> Could not create type cargo due to java.lang.NoClassDefFoundError: org/apache/commons/discovery/resource/ClassLoaders
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':cargoRunLocal'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
BUILD FAILED
This is the cargo dependency in my build.gradle:
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.1.1'
}
And this is the localDeploy.gradle where I added the Cargo config:
apply plugin: 'com.bmuschko.cargo'
cargo {
containerId = 'tomcat7x'
local {
installer {
installUrl = 'https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.67/bin/apache-tomcat-7.0.67.zip'
downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/extract")
}
}
}
It seems common discovery jar file not loaded properly.
I guess you should enable org.gradle.debug=true in gradle.properties and try debuging it -
When set to true, Gradle will run the build with remote debugging enabled, listening on port 5005. Note that this is the equivalent of adding -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 to the JVM command line and will suspend the virtual machine until a debugger is attached.
Make sure the dependencies are transitive if you have the below then make it more specific
configurations.all {
transitive = false
}
example
configurations.compile {
transitive = false
}
This way gradle will download all the dependencies for cargo

Categories