Why can't Gradle resolve org.connectbot.jbcrypt:jbcrypt:1.0.0 from the Maven Central Repository? - maven

I'm using Gradle 6.9 and here is my build.gradle file:
plugins {
id "groovy"
id "java"
}
group "com.matthiasdenu"
version "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven {
url 'https://repo.jenkins-ci.org/releases/'
}
}
ext {
jobDslVersion = "1.77"
jenkinsVersion = "2.252"
}
sourceSets {
jobs {
groovy {
srcDirs "jobs"
compileClasspath += main.compileClasspath
}
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
dependencies {
compile("org.jenkins-ci.main:jenkins-war:${jenkinsVersion}"){
// https://github.com/sheehan/job-dsl-gradle-example/issues/87
exclude group: "org.jenkins-ci.ui", module: "bootstrap"
}
}
test {
useJUnitPlatform()
}
This is the error message I'm getting:
Execution failed for task ':compileTestGroovy'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not find org.connectbot.jbcrypt:jbcrypt:1.0.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/org/connectbot/jbcrypt/jbcrypt/1.0.0/jbcrypt-1.0.0.pom
- https://repo.jenkins-ci.org/releases/org/connectbot/jbcrypt/jbcrypt/1.0.0/jbcrypt-1.0.0.pom
Required by:
project : > org.jenkins-ci.main:jenkins-war:2.252 > org.jenkins-ci.main:jenkins-core:2.252
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
What's odd is that the 1.0.0 artifact doesn't show up at https://repo.maven.apache.org/maven2/org/connectbot/jbcrypt/. I also noticed that the urls don't quite match either. Like if I try to get v1.0.1 it doesn't resolve either because it expects an extra "jbcrypt" for the group name.
I have this problem even when using the latest jenkins-war release (2.304).
What's going on?

You have to add the Jenkins public repository to your configuration. It contains all libraries available in the releases repository and all required dependencies.
The file exists: https://repo.jenkins-ci.org/public/org/connectbot/jbcrypt/jbcrypt/1.0.0/jbcrypt-1.0.0.jar
repositories {
mavenCentral()
maven {
url 'https://repo.jenkins-ci.org/public/'
}
}

Related

Unable to publish a gradle Jar artifact to a sonatype repository

I am following instructions in the Sonatype documentation for publishing a gradle project.
I have the following gradle version.
$ ./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: 1.8.0_181 (Oracle Corporation 25.181-b13)
OS: Mac OS X 10.16 x86_64
When I try to use the uploadArchives task as given in their example, I get the following error:
$ ./gradlew uploadArchives
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/ferozed/stash/libs/mask-json-field-transform/build.gradle' line: 167
* What went wrong:
A problem occurred evaluating root project 'mask-json-field-transform'.
> Could not find method uploadArchives() for arguments [build_6yphclnk6m8p3rtmq5h7m56li$_run_closure12#19fbeecd] on root project 'mask-json-field-transform' of type org.gradle.api.Project.
This is my build.gradle file
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'gradle.plugin.com.github.johnrengelman:shadow:7.1.2'
}
}
plugins {
id 'java' // so that we can use 'implementation', 'testImplementation' for dependencies
id 'maven-publish'
id 'signing'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
jcenter()
mavenCentral()
maven {
url = "https://packages.confluent.io/maven"
}
maven {
url = "https://jitpack.io"
}
}
group = 'io.github.ferozed.kafka.connect'
version = '0.1'
dependencies {
// Kafka
implementation group: 'org.apache.kafka', name: 'connect-api', version: '3.3.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.1'
implementation 'com.github.jcustenborder.kafka.connect:connect-utils:0.7.173'
implementation 'com.github.jcustenborder.kafka.connect:kafka-connect-transform-common:0.1.0.14'
//test
testImplementation(platform('org.junit:junit-bom:5.9.0'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation("io.mockk:mockk:1.9.2")
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/avro", "src/main/resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
plugins.withId("com.github.johnrengelman.shadow"){
//this block requires the java plugin to be applied first.
plugins.withId("java"){
shadowJar {
//We are overriding the default jar to be the shadow jar
classifier = null
exclude 'META-INF'
exclude 'META-INF/*.INF'
exclude 'META-INF/license/*'
}
jar {
manifest {
attributes(
'Built-By' : System.properties['user.name'],
'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
)
}
}
tasks.build.dependsOn tasks.shadowJar
tasks.shadowJar.mustRunAfter tasks.jar
tasks.shadowJar.mustRunAfter tasks.javadocJar
tasks.shadowJar.mustRunAfter tasks.sourcesJar
}
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = 'Mask Json Field Transform'
description = 'A kafka connect transform to remove the value of a sensitive field in a json document.'
url = 'https://github.com/ferozed/mask-json-field-transform'
properties = [
myProp: "value",
"prop.with.dots": "anotherValue"
]
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'ferozes'
name = 'Feroze Daud'
email = 'ferozed.oss#gmail.com'
}
}
scm {
connection = 'scm:git:git#github.com:ferozed/mask-json-field-transform.git'
developerConnection = 'scm:git:git#github.com:ferozed/mask-json-field-transform.git'
url = 'https://github.com/ferozed/mask-json-field-transform'
}
}
}
}
}
signing {
sign configurations.archives
sign publishing.publications.mavenJava
}
tasks.signArchives.dependsOn tasks.shadowJar
artifacts {
archives javadocJar, sourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { deployment -> signing.signPom(deployment) }
repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Example Application'
packaging 'jar'
// optionally artifactId can be defined here
description 'A kafka connect transform to remove the value of a sensitive field in a json document.'
url 'https://github.com/ferozed/mask-json-field-transform'
scm {
connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'
url 'https://github.com/ferozed/mask-json-field-transform'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'ferozed'
name 'Feroze Daud'
email 'feroz#gmail.com'
}
}
}
}
}
}
What am I doing wrong?
First and foremost, you may not need to 'fix the error' so to speak, in that it appears the problematic code MAY be able to be outright deleted. However...
To fix the error...
Could not find method uploadArchives() for arguments [build_6yphclnk6m8p3rtmq5h7m56li$_run_closure12#19fbeecd] on root project 'mask-json-field-transform' of type org.gradle.api.Project.
This is telling us that uploadArchives is not valid. See immediately below.
I believe you may need to use the maven plugin to access this functionality.
https://github.com/siddeshbg/gradle-uploadArchives/blob/master/README.md
to do this, add:
id 'maven'
to your plugins{}
block.
The above example explains that the maven plugin is responsible for doing this
The Maven plugin adds support for deploying artifacts to Maven repositories
It is worth considering also that the author of the above repository claims:
This is the legacy publishing mechanism, should not be used in newer
builds
Now... on to the better solution, forgetting the maven plugin, in favor of the maven-publish plugin you're already using...
I do not personally work with Maven often enough to know what other mechanisms one should use, but Google suggests that perhaps the maven-publish plugin you're using might do this WITHOUT the 'uploadArchives{}' portion of your code that is causing the error.
See:
https://docs.gradle.org/current/userguide/publishing_maven.html
Per this page, it would seem the entire uploadArchives block is unnecessary

Gradle 5: Failed to apply plugin [id 'aspectj']

I am trying to run a build.gradle file that looks like this and which returns an error on line apply plugin: 'aspectj'
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/release" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/libs-milestone" }
maven { url "https://maven.eveoh.nl/content/repositories/releases" }
}
dependencies {
classpath "nl.eveoh:gradle-aspectj:2.0"
}
}
apply plugin: 'aspectj'
jar {
manifest {
attributes(
"Created-By": "Iuliana Cosmina",
"Specification-Title": "Pro Spring 5",
"Main-Class": "com.apress.prospring5.ch5.AspectJDemo",
"Class-Path": configurations.compile.collect { it.getName() }.join(' ')
)
}
}
The error message is as follows:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/me/Spring/pro-spring-5-master/chapter05/aspectj-aspects/build.gradle' line: 17
* What went wrong:
A problem occurred evaluating project ':chapter05:aspectj-aspects'.
> Failed to apply plugin [id 'aspectj']
> Could not find method deleteAllActions() for arguments [] on task ':chapter05:aspectj-aspects:compileJava' of type org.gradle.api.tasks.compile.JavaCompile.
What am I doing wrong here?
AspectJ is not compatible with Gradle 5.0 - see issues #7861 and #8063.
The most easy might be to replace the plugin; eg. with io.freefair.aspectj.post-compile-weaving, because aspectj.gradle had been last updated 2 years ago (it seems abandoned).
I have fixed the issue and published a new version to jcenter. Find it here: https://bintray.com/zebalu/releases/gradle-aspectj
currently you need this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.github.zebalu:gradle-aspectj:2.3.3'
}
}
apply plugin: 'gradle-aspectj'
// rest of your code

Gradle 4.8+ breaks ivy publish with custom configurations

I've got a gradle file which is working in some ancient version of gradle but I want to upgrade to gradle 5.0. Unfortunately its using ivy rather than maven to publish its jars. I've cut it down to a simple test case.
I'm not sure if I'm missing something or its a bug or what. I've attached the gradle below. I'm running it
./gradlew wrapper && ./gradlew publish --info && cat build/publications/ivy/ivy.xml
It works as expected with 4.7. It publishes the main jar and the source jar and adds the dependencies.
If I switch to 4.8 it breaks, it only publishes the source jar, main jar and dependencies are missing.
If I switch to 4.8 and comment out the configurations bit it publishes the main jar and dependencies again.
Perhaps there's a new way of doing things but if so I've failed to find where its documented. Here's the source build.gradle.
plugins {
id 'java'
id 'ivy-publish'
}
sourceSets {
testSupport {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
test {
java {
compileClasspath += testSupport.output
runtimeClasspath += testSupport.output
}
}
}
dependencies {
compile group: 'com.ibm.icu', name: 'icu4j', version: '58.2'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
compile group: 'io.swagger', name: 'swagger-parser', version: '1.0.32'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
task testSupportJar(type: Jar) {
from sourceSets.testSupport.output
appendix "test-support"
}
task testSupportSourceJar(type: Jar) {
from sourceSets.testSupport.java.srcDirs
appendix "test-support-sources"
}
artifacts {
archives sourceJar
archives testSupportJar
archives testSupportSourceJar
}
publishing {
repositories {
ivy {
name = 'myRepo'
url = "file://${buildDir}/repo"
layout "pattern", {
artifact "[organisation]/[module]/[revision]/jars/[artifact].[ext]"
ivy "[organisation]/[module]/[revision]/ivys/ivy-[revision].xml"
}
}
}
publications {
ivy(IvyPublication) {
organisation = 'com.example.com'
// If you comment out the configurations below it will generate sensible ivy.xml
configurations {
"compile" {}
"runtime" {}
}
from components.java
artifact(sourceJar) {
type "source"
extension "src.jar"
conf "runtime"
}
}
}
}
wrapper {
// 4.7 works but 4.8+ doesn't.
gradleVersion = '4.7'
}
Oh man I just figured it out. Its the relative ordering of from components.java and the configurations element bits. If configurations is first it seems to take precedence over from components.java and the latter is seemingly ignored. If you put from components.java before configurations it works and you don't have to manually declare the configs it generates by default any more.
FFS gradle.

gradle Could not resolve all dependencies for configuration ':compile'

I have a dependencies problem I need help with.
I can build EGLSource fin on its own.
But when i try to build EGL2JS then I get this error:
Error message:
:compileJava
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not find :swt-64:.
Searched in the following locations:
https://repo1.maven.org/maven2//swt-64//swt-64-.pom
https://repo1.maven.org/maven2//swt-64//swt-64-.jar
Required by:
:EGL2JS:unspecified > EGL2JS:EGLSource:unspecified
Build and settings files for the two projects: EGLSource and EGL2JS.
EGL2JS: settings.gradle
include ':EGLSource'
project(':EGLSource').projectDir = new File(settingsDir, '../EGLSource')
EGL2JS: build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile project(':EGLSource')
}
sourceSets {
main {
java.srcDirs = ['src', 'target/generated-sources']
}
}
EGLSource: build.gradle
apply plugin: 'java'
repositories {
flatDir {
dirs 'lib'
}
}
dependencies {
compile name: 'swt-64'
}
sourceSets {
main {
java.srcDirs = ['src', 'target/generated-sources/antlr4']
}
}
Why is EGL2JS complaining about a dependency in EGLSource?
I could add the swt-64.jar to EGL2JS. But EGL2JS does not directly depend on swt-64.jar so I don't like that solution.
Are there other ways to resolve this dependency?
For reasons I don't understand this makes a difference.
Removing flatFile from repositories
and changing dependencies
from:
compile name: 'swt-64'
to:
dependencies {
compile fileTree(dir: 'lib', include: 'swt-64.jar')
}
Also gradle dependencies not longer shows swt-64 failed.

How to exclude dependencies in the POM file generated by the Gradle

I'm using the "maven" plugin to upload the artifacts created by Gradle build to Maven central repository. I'm using a task similar to the following one:
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.project {
name 'Example Application'
packaging 'jar'
url 'http://www.example.com/example-application'
scm {
connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
url 'http://foo.googlecode.com/svn/trunk/'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
}
However the POM file created by this task does not report correctly the dependencies that have been excluded in my Gradle build file. For example:
dependencies {
compile('org.eclipse.jgit:org.eclipse.jgit.java7:3.5.2.201411120430-r') { exclude module: 'commons-logging' }
compile('com.upplication:s3fs:0.2.8') { exclude module: 'commons-logging' }
}
How to have excluded dependencies managed correctly in the resulting POM file?
You can simply override the dependencies of the pom by filtering out the unwanted dependencies, e.g. to exclude junit you can add the following lines to the mavenDeployer configuration:
pom.whenConfigured {
p -> p.dependencies = p.dependencies.findAll {
dep -> dep.artifactId != "junit"
}
}
The problem was that in the exclude definition was not specified the group but only the module.
Adding the both of them the exclusions are added correctly in the POM file. For example:
compile('org.eclipse.jgit:org.eclipse.jgit.java7:3.5.2.201411120430-r') {
exclude group: 'commons-logging', module: 'commons-logging'
}
compile('com.upplication:s3fs:0.2.8') {
exclude group: 'commons-logging', module: 'commons-logging'
}
Using 'exclude' on a Gradle dependency is normally the correct answer, but I still needed to remove some of my "runtimeOnly" dependencies from the POM that led me to this StackOverflow page. My testing using Gradle 4.7 seems to show that using "compileOnly" leaves the dependency out of the pom entirely, but "runtimeOnly" adds a "runtime" dependency in the pom, which in my case, is not what I wanted. I couldn't figure out a "standard" Gradle way of leaving runtime dependencies out of the POM.
The pom.whenConfigured method shown in another answer works for legacy "maven" plugin publishing, but doesn't work for the newer "maven-publish" plugin. My experimentation led to this for "maven-publish":
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom.withXml {
asNode().dependencies.dependency.each { dep ->
if(dep.artifactId.last().value().last() in ["log4j", "slf4j-log4j12"]) {
assert dep.parent().remove(dep)
}
}
}
}
}
}

Resources