Gradle maven publish doesn't work for first version - java

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.

Related

Publish snapshot Jar in codeArtifact returns bad request

I am starting to evaluate AWS codeArtifact service. Currently I am hosting maven artifacts in an on-premises Nexus repository. We use snapshots and release artifacts as expected using gradle to describe project's dependencies and repositories to work with. I added the following code section to the gradle file. Version parameter is being hardcoded for testing purposes.
publishing {
publications {
mavenJava(MavenPublication) {
version = '1.0.0-SNAPSHOT'
from components.java
}
}
repositories {
maven {
url "${codeArtifactUrl}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
When I execute the gradle publish task it is returning me the following:
Could not find metadata com.turner.lrs.packages:lrs-packages-commons:1.0.0-SNAPSHOT/maven-metadata.xml in remote (https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/)
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/lrs-packages-commons-1.0.0-20220914.171546-1.jar
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/lrs-packages-commons-1.0.0-20220914.171546-1.jar.sha1
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/lrs-packages-commons-1.0.0-20220914.171546-1.jar.md5
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/lrs-packages-commons-1.0.0-20220914.171546-1.pom
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/lrs-packages-commons-1.0.0-20220914.171546-1.pom.sha1
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/lrs-packages-commons-1.0.0-20220914.171546-1.pom.md5
Could not find metadata com.turner.lrs.packages:lrs-packages-commons/maven-metadata.xml in remote (https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/)
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/maven-metadata.xml
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/maven-metadata.xml
> Task :lrs-packages-commons:publishMavenJavaPublicationToMavenRepository
Could not transfer metadata com.turner.lrs.packages:lrs-packages-commons:1.0.0-SNAPSHOT/maven-metadata.xml from/to remote (https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/): Could not write to resource 'com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/maven-metadata.xml'
Could not transfer metadata com.turner.lrs.packages:lrs-packages-commons/maven-metadata.xml from/to remote (https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/): Could not write to resource 'com/turner/lrs/packages/lrs-packages-commons/maven-metadata.xml'
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lrs-packages-commons:publishMavenJavaPublicationToMavenRepository'.
> Failed to publish publication 'mavenJava' to repository 'maven'
> Could not write to resource 'https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/maven-metadata.xml'.
> Could not PUT 'https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0-SNAPSHOT/maven-metadata.xml'. Received status code 400 from server: Bad Request
* 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 6s
4 actionable tasks: 2 executed, 2 up-to-date
The jar ends up being published but with an "Unfinished" status
However if I remove the word SNAPSHOT, everything works as expected, artifact is published and its status is "Published"
publishing {
publications {
mavenJava(MavenPublication) {
version = '1.0.0'
from components.java
}
}
repositories {
maven {
url "${codeArtifactUrl}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
.
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0/lrs-packages-commons-1.0.0.jar
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0/lrs-packages-commons-1.0.0.jar.sha1
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0/lrs-packages-commons-1.0.0.jar.md5
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0/lrs-packages-commons-1.0.0.pom
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0/lrs-packages-commons-1.0.0.pom.sha1
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/1.0.0/lrs-packages-commons-1.0.0.pom.md5
Could not find metadata com.turner.lrs.packages:lrs-packages-commons/maven-metadata.xml in remote (https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/)
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/maven-metadata.xml
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/maven-metadata.xml.sha1
Upload https://gmsc-esb-817672308881.d.codeartifact.us-east-1.amazonaws.com/maven/esb/com/turner/lrs/packages/lrs-packages-commons/maven-metadata.xml.md5
BUILD SUCCESSFUL in 6s
Any clue?

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.

Error while performing push command in git

Using the guide https://www.youtube.com/watch?v=7RHYDNSRSOs I want to deploy the application to Heroku. However, git push heroku master throws an error:
:compileJava NO-SOURCE
:processResources NO-SOURCE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRepackage'.
> Unable to find main class
* 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: 15.555 secs
! ERROR: Failed to run Gradle!
We're sorry this build is failing. If you can't find the issue in application
code, please submit a ticket so we can help: https://help.heroku.com
You can also try reverting to the previous version of the buildpack by running:
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
Thanks,
Heroku
! Push rejected, failed to compile Gradle app.
! Push failed
The project normally works during compilation in IntelliJ. They work without a problem.

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.

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