Cannot deploy locally using Cargo plugin for Gradle - java

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

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.

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'
}
}

How do I fix my React Native failing Android build in Gradle? com.google.firebase:firebase-iid is being requested by various other libraries

I have tried generating a signed APK according to the instructions here: https://facebook.github.io/react-native/docs/signed-apk-android
When running ./gradlew assembleRelease, I get a build error as seen below. My app uses Google Firebase for authentication and tipsi-stripe as one of its main libraries. It is a detached Expo build.
I have tried adding additional dependencies, including Firebase core in app/build.gradle
The error in the terminal.
❯ ./gradlew assembleRelease
Parallel execution is an incubating feature.
{..}
> Task :tipsi-stripe:compileReleaseRenderscript FAILED
> Task :app:checkDevKernelReleaseClasspath FAILED
> Task :react-native-firebase:compileReleaseRenderscript FAILED
FAILURE: Build completed with 3 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Failed to capture fingerprint of input files for task ':tipsi-stripe:compileReleaseRenderscript' property 'importDirs' during up-to-date check.
> The library com.google.firebase:firebase-iid is being requested by various other libraries at [[16.2.0,16.2.0]], but resolves to 17.0.4. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Failed to capture fingerprint of input files for task ':app:checkDevKernelReleaseClasspath' property 'compileClasspath' during up-to-date check.
> The library com.google.firebase:firebase-iid is being requested by various other libraries at [[16.2.0,16.2.0]], but resolves to 17.0.4. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
==============================================================================
3: Task failed with an exception.
-----------
* What went wrong:
Failed to capture fingerprint of input files for task ':react-native-firebase:compileReleaseRenderscript' property 'importDirs' during up-to-date check.
> The library com.google.firebase:firebase-iid is being requested by various other libraries at [[16.2.0,16.2.0]], but resolves to 17.0.4. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
==============================================================================
BUILD FAILED in 18s
38 actionable tasks: 3 executed, 35 up-to-date
My app/build.gradle: https://gist.github.com/christopheragnus/35c13d31976c889268b663cbf1654ead
My root /build.gradle: https://gist.github.com/christopheragnus/e6f506d6882ad37ce7656140a240f5bf
EDIT:
I tried changing /build.gradle to use version 16.2.0,
resolutionStrategy {
...
force 'com.google.firebase:firebase-iid:16.2.0'
}
This resulted in a different but same type of error:
> Task :tipsi-stripe:compileReleaseRenderscript FAILED
> Task :app:checkDevKernelReleaseClasspath FAILED
> Task :react-native-firebase:compileReleaseRenderscript FAILED
Could not resolve all files for configuration ':tipsi-stripe:releaseCompileClasspath'.
> Could not find com.google.android.gms:play-services-measurement-api:11.8.0.
...
> Could not find com.google.android.gms:play-services-measurement-base:11.8.0.
...
> Could not find com.google.android.gms:play-services-ads-identifier:11.8.0.

grgit NoClassDefFoundError

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.

Gradle maven publish doesn't work for first version

with a build.gradle file containing:
apply plugin: 'java'
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
snapshotRepository (url: mavenSnapshotRepoUrl)
repository (url: mavenRepoUrl) {
authentication (userName: mavenRepoUsername, password: mavenRepoPassword)
}
pom {
//groupId = project.group
artifactId = 'myapp'
//version = project.version
}
}
}
}
when I run the command uploadArchives, I get the following error:
$ gradlew uploadArchives
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:uploadArchives FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'archives'
> Error deploying artifact 'mycompany:myapp:jar': Error retrieving
previous build number for artifact 'mycompany:myapp:jar': repository
metadata for: 'snapshot mycompany:myapp:0.0.
1-SNAPSHOT' could not be retrieved from repository: remote due to an
error: Authorization failed: Access denied to: http://myserver\
/repository/snapshots/mycompany/myapp/0.0.1-SNAPSHOT/maven-metadata.xml
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I've triple checked my userName and password. Is there something I'm missing or is this usual for an initial publish?
I had very similar error message coming up today when I executed
$ gradle uploadArchives
on my Mac Book. My Mac was sitting behind Proxy server of the job. I had a remote public Artifactory repository server into which I tried upload my jar.
For the last few months, I have had dozens of problems due to Proxy intervension. I thought this error must have something to do with Proxy.
I moved to AWS EC2 instance. I cloned my gradle project on the ec2 instance, and did the same operation:
$ gradle uploadArchives
Success!
No change required in the code.
Simpler route of HTTP connection made me happy.

Categories