I am currently trying to get the URL of the Maven Deployer in a task, but it is failing. I am able to get the Maven Deployer itself, but I apparently cannot create an object of type RemoteRepository when calling the method mavenDeployer.getRepository().
Here is the build.gradle file:
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///path/to/maven/repo/")
}
}
}
In my Task :
Upload uploadArchives = project.getTasks().withType(Upload.class)
.findByName(BasePlugin.UPLOAD_ARCHIVES_TASK_NAME);
for(ArtifactRepository repo : uploadArchives.getRepositories()) {
if (repo instanceof MavenDeployer) {
MavenDeployer mavenDeployer = (MavenDeployer) repo;
System.out.println(repo) //Returns org.apache.maven.artifact.ant.RemoteRepository
RemoteRepository l = (RemoteRepository) mavenDeployer.getRepository() // Crashes here
}
}
It displays:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':myTask'.
> org/apache/maven/artifact/ant/RemoteRepository
The stacktrace ends by:
Caused by: java.lang.ClassNotFoundException: org.apache.maven.artifact.ant.RemoteRepository
Apparently, Gradle cannot find the class org.apache.maven.artifact.ant.RemoteRepository, even after I imported it successfully. If I comment out the line that creates the class MavenDeployer, it works fine.
Is there a way to fix this? If not, is there another way to get the repository URL of the Maven Deployer?
The build script classloader does not expose RemoteRepository. but you should be able to resolve the information thanks for groovys ducktyping:
task printDeployerUrl << {
tasks.withType(Upload) { uploadTask ->
for(ArtifactRepository repo : uploadArchives.getRepositories()) {
if (repo instanceof MavenDeployer) {
MavenDeployer mavenDeployer = (MavenDeployer) repo;
System.out.println(repo.repository.url)
}
}
}
}
Related
I am trying to install a package but it seems to be going to https://jitpack.io/ which is having an outage at the moment. I have a personal proxy repo which already has the image I want but because the dependent code has 42.2.+ it is looking for some other data which I think I also have but it is resolving to jitpack.
cat <<EOT > $HOME/.gradle/init.gradle
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:0.70.5"
}
}
repositories {
mavenLocal()
maven {
url = uri('https://mine/')
credentials {
...
}
}
<-- tried putting here
}
<-- and here
This is the block I wanted to add
dependencyResolutionManagement {
repositories {
maven {
url = uri('https://mine/')
credentials {
...
}
}
}
}
But it is saying signature not found.
There's a closed issue for this but I can't find an example on how to do it. I tried to copy the one from the Issue OP but it didn't appear to work
settingsEvaluated {
it.dependencyResolutionManagement {
repositories {
maven {
url = uri('https://mine/')
credentials {
...
}
}
}
}
}
In the end I get this
[RUN_GRADLEW] A problem occurred configuring project ':rn-pendo-sdk'.
[RUN_GRADLEW] > Could not resolve all files for configuration ':rn-pendo-sdk:implementation'.
[RUN_GRADLEW] > Could not resolve sdk.pendo.io:pendoIO:2.19.+.
[RUN_GRADLEW] Required by:
[RUN_GRADLEW] project :rn-pendo-sdk
[RUN_GRADLEW] > Failed to list versions for sdk.pendo.io:pendoIO.
[RUN_GRADLEW] > Unable to load Maven meta-data from https://www.jitpack.io/sdk/pendo/io/pendoIO/maven-metadata.xml.
[RUN_GRADLEW] > Could not GET 'https://www.jitpack.io/sdk/pendo/io/pendoIO/maven-metadata.xml'. Received status code 521 from server:
My problem is that I develop a custom Gradle plugin and I need to get access to repositories which belongs to Settings object, particular PluginManagement object.
settings.gradle file of project which I connect my custom plugin looks like this:
pluginManagement {
resolutionStrategy {
}
repositories {
maven {
credentials {
username = System.getenv("USERNAME")
password = System.getenv("PASSWORD")
}
url = uri("${System.getenv("nexusUrl")}/repository/***")
}
}
}
There is my code I want to just list url of all repositories:
project.afterEvaluate {
val gradle = project.rootProject.gradle as org.gradle.invocation.DefaultGradle
val settings = gradle.settings as org.gradle.initialization.DefaultSettings
settings.pluginManagement.repositories.forEach { repo ->
run {
repo as MavenArtifactRepository
println(repo.url)
}
}
}
I expect the following output result:
https://nexus_url/repository/***
But instead I get 'null' in output.
But when I run this code from custom task I get expected result:
tasks.create("abc") {
project.afterEvaluate {
val gradle = project.rootProject.gradle as org.gradle.invocation.DefaultGradle
val settings = gradle.settings as org.gradle.initialization.DefaultSettings
settings.pluginManagement.repositories.forEach { repo ->
run {
repo as MavenArtifactRepository
println(repo.url)
}
}
}
}
Why are in execution time this repositories not empty and what is the best way to access them from Project object?
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 tries to publish maven's POM twice (through uploadArchives task)
I have multiproject build with apply from:s where specified how to publish my artifacts (publish-jars.gradle):
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
build.dependsOn(sourcesJar)
artifacts {
archives sourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'releases repo') {
authentication(
userName: rootProject.properties.get('artifactory.username'),
password: rootProject.properties.get('artifactory.token')
)
}
snapshotRepository(url: 'snapshots repo) {
authentication(
userName: rootProject.properties.get('artifactory.username'),
password: rootProject.properties.get('artifactory.token')
)
}
}
}
}
def installer = install.repositories.mavenInstaller
def deployer = uploadArchives.repositories.mavenDeployer
[installer, deployer]*.pom*.whenConfigured { pom ->
pom.project {
packaging 'jar'
}
pom.withXml {
asNode().dependencies.'*'.each {
if (it.scope*.value != null) {
it.scope*.value = 'compile'
}
}
asNode().dependencyManagement.dependencies.'*'.each {
if (it.scope*.value != null) {
it.scope*.value = 'compile'
}
}
def repos = asNode().appendNode('repositories')
project.repositories.findAll { it.name != 'MavenLocal' }.each {
def repo = repos.appendNode('repository')
repo.appendNode('id', it.name)
repo.appendNode('name', it.name)
repo.appendNode('url', it.url)
}
}
if (project.hasProperty('pomConfigurer')) {
pom.withXml(pomConfigurer)
}
}
install.dependsOn build
uploadArchives.dependsOn build
task 'publish-snapshot'() {
dependsOn uploadArchives
}
task publish() {
dependsOn uploadArchives
}
and I have module which contains only parent pom (:my-project:parent):
dependencyManagement {
generatedPomCustomization {
enabled = true
}
}
ext.pomConfigurer = {
// some pom configuration
}
and finally I have root project build.gradle:
allprojects {
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
}
subprojects {
apply from: file('publish-jars.gradle')
}
Is it gradle bug, or am I doing something wrong?
UPD: Gradle output
> Task :my-project:some-module:compileKotlin
> Task :my-project:some-other-module:compileKotlin
> Task :my-project:some-another-module:compileKotlin
> Task :my-project:some-yet-another-module:compileKotlin
> Task :my-project:one-more-module:compileKotlin
> Task :my-project:last-module:compileTestKotlin
> Task :mkGitTag
##teamcity[setParameter name='env.release_tag' value='v2.1.1-rc20']
> Task :my-project:parent:uploadArchives
Could not transfer artifact groupname:parent:pom:2.1.1-rc20 from/to remote (https://releases repo): Failed to transfer file: https://releases repo/groupname/parent/2.1.1-rc20/parent-2.1.1-rc20.pom. Return code is: 409, ReasonPhrase: Conflict.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':my-project:parent:uploadArchives'.
> Could not publish configuration 'archives'
> Failed to deploy artifacts: Could not transfer artifact groupname:parent:pom:2.1.1-rc20 from/to remote (https://releases repo): Failed to transfer file: https://releases repo/groupname/parent/2.1.1-rc20/test-parent-2.1.1-rc20.pom. Return code is: 409, ReasonPhrase: Conflict.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
43 actionable tasks: 43 executed
In my build.gradle script, publishing works when the groupId is left undefined. I would like to use "org.company.foobar.common" for the groupId.
When I uncomment the groupId lines in the following build.gradle script, I receive an error. Below the script is the execution results when this groupId is defined.
buildscript {
repositories {
maven { url "http://tribe.ust.doj.gov:8085/artifactory/jcenter/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/MavenCentral/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/gradlePlugins/"}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
repositories {
maven { url "http://tribe.ust.doj.gov:8085/artifactory/jcenter/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/MavenCentral/"}
maven { url "http://tribe.ust.doj.gov:8085/artifactory/gradlePlugins/"}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
def getArtifactoryUrl() {
return "http://tribe.ust.doj.gov:8085/artifactory/"
}
allprojects {
repositories {
def artifactoryMcentralUrl = getArtifactoryUrl() + "MavenCentral/"
maven {url artifactoryMcentralUrl }
}
}
dependencies {
}
sourceSets {
main {
java {
srcDir "/src"
}
}
}
//project.group = 'org.company.foobar.common'
task printProps {
doLast {
println artifactory_user
println artifactory_contextUrl
//println project.group
}
}
publishing {
publications {
mavenJava(MavenPublication) {
//groupId project.group
artifactId project.getName()
version '1.0.0'
from components.java
}
}
}
artifactory {
def artifactoryUrl = getArtifactoryUrl()
contextUrl = artifactoryUrl
publish {
repository {
repoKey = 'libs-snapshot-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publications('mavenJava')
publishArtifacts = true
publishPom = true
}
}
}
The output from "gradle artifactoryPublish" when using the groupId (uncommented) is:
$ gradle artifactoryPublish
:generatePomFileForMavenJavaPublication
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:artifactoryPublish
Deploying artifact: http://tribe.ust.doj.gov:8085/artifactory/libs-snapshot-local/org/company/foobar/common/kambucha/1.0.0/kambucha-1.0.0.jar
:artifactoryPublish FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':artifactoryPublish'.
> java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors:
The repository 'libs-snapshot-local' rejected the resolution of an artifact 'libs-snapshot-local:org/company/foobar/common/kambucha/1.0.0/kambucha-1.0.0.jar' due to conflict in the snapshot release handling policy. Status code: 409
* 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: 1.84 secs
As it seems, you are trying to publish a RELEASE artifact to a SNAPSHOT repository. When using maven repositories in Artifactory, you will need to make sure that you are following both the Maven layout, and the release / snapshot policy.
In this specific example it seems that your issue is as following:
Artifactory, following maven policy, is recognizing the following path:
'libs-snapshot-local:org/company/foobar/common/kambucha/1.0.0/kambucha-1.0.0.jar' as a release, while the repository is set to handle only snapshots. For this specific path to work, and in case this is really a snapshot artifact, you will need to change the path to be:
libs-snapshot-local:org/company/foobar/common/kambucha/1.0.0-SNAPSHOT/kambucha-1.0.0-SNAPSHOT.jar
If this is a release, change your deployment path to use 'libs-release-local' repository
You can read more on the repository configuration here