How do I set the dependencyResolutionManagement on init.gradle? - gradle

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:

Related

How to access PlaginManager repositories from custom gradle plugin

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?

Creating a maven wrapper pom.xml from gradle: can't create the <build> element

How do I set the sourceDirectory, testSourceDirectory and build plugins in a pom.xml that I'm creating using the gradle maven-plugin's pom DSL?
When I add build without a Closure to my DSL section, it's ok.. but when I add build { /* anything else, like actual compile plugins */} it gives me this error:
Execution failed for task ':mavenWrapper'.
> No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model
I'm guessing that gradle is treating build as the task rather than the DSL verb generated by org.sonatype.maven.polyglot.groovy.builder.ModelBuilder.
Is there a way to force build to be treated as part of the DSL? Can it be cast or something?
Right now I'm working around this by using .withXml but it's massively verbose and much less maintainable.
Here's an abbreviated version of what I've got working:
task mavenWrapper {
doLast {
delete 'pom.xml', 'mvnw', 'mvnw.cmd'
pom {
project {
packaging 'pom'
repositories {
repository {
id 'spring-milestones'
name 'Spring Milestones'
url 'https://repo.spring.io/libs-milestone'
snapshots {
enabled 'false'
}
}
}
properties {
'kotlin.compiler.incremental' 'true'
}
/* ******** Problem is here
build {
plugins {
plugin {
// ... etc. etc.
}
}
}
******* */
dependencyManagement {
dependencies {
dependency {
groupId 'org.jetbrains.kotlin'
artifactId 'kotlin-stdlib-jre8'
version "${kotlin_version}"
scope 'compile'
}
}
}
}
}.withXml {
// Workaround for the missing build { ... } section above.
asNode().appendNode('build').appendNode('plugins')
// etc. etc.
}.writeTo("${projectDir}/pom.xml")
exec {
commandLine 'mvn', '-N', 'io.takari:maven:wrapper', '-Dmaven=3.5.0'
}
}
}

Gradle - Get the MavenDeployer URL

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

Unable to reference gradle.properties in script plugin

I am creating a script plugin to reference the ivy repository holding my orgs gradle plugins. My code right now is:
repository.gradle
repositories {
ivy {
credentials {
username = artifactory_user
password = artifactory_password
}
url 'https://ourUrl/artifactory/repoName'
layout "pattern", {
ivy '[organization]/[module]/[revision]/ivy-[revision].xml'
artifact '[organisation]/[module]/[revision]/[artifact]-[revision].[ext]'
}
}
}
Then, in the build.gradle file,
build.gradle
buildscript {
apply from: https://ourUrl/assets/repository.gradle, to: buildscript
dependencies { classpath group: 'ourGrp', name: 'artifactName', version: '1.0.0' }
}
In my gradle.properties file:
gradle.properties
artifactory_user=username
artifactory_password=password
The error message I recieve is this:
What went wrong:
A problem occurred evaluating script.
Could not find property 'artifactory_user' on Credentials [username: null].
Any suggestions for how I can resolve this? I would like to avoid any further impact to the build.gradle file if possible.
This exact question was asked in the gradle forums. I'll paste the working workaround so it won't get lost during relinking or something:
repository.gradle:
repositories {
ivy {
credentials {
username = artifactory_user
password = artifactory_password
}
url 'https://ourUrl/artifactory/repoName'
layout "pattern", {
ivy '[organization]/[module]/[revision]/ivy-[revision].xml'
artifact '[organisation]/[module]/[revision]/[artifact]-[revision].[ext]'
}
}
}
ext.extRepo = repositories
build.gradle:
buildscript {scriptHandler->
apply from: 'https://ourUrl/assets/repository.gradle'
repositories.addAll(extRepo)

Trouble injecting the build block while exporting a Maven pom.xml file from gradle

task writeNewPom {
pom {
project {
/*
build {
plugins {
plugin {
groupId 'GROUP_ID'
artifactId 'maven-ipcentral-plugin'
version '4.7'
executions {}
configuration {
url "http://CENTRAL_REPORTING_SERVER"
logfileprefix "test"
ipcProject = true
businessUnit "FOUR_DIGIT_CODE"
componentEditorsGrouper "ccp-dev"
assetEditorsGrouper "ccp-dev"
username "USERNAME"
}
}
}
}
*/
pluginRepositories {
pluginRepository {
id 'ipcentral-snapshots'
name 'IPCentral Snapshot Repository'
url 'http://PLUGIN_SOURCE/'
snapshots {
enabled = false
}
releases {
enabled = true
}
}
}
profiles {
profile {
id 'inject-cec-credentials'
activation {
activeByDefault = true
}
properties {
username = "USERNAME"
}
}
}
}
}.writeTo("ipcentral/pom.xml")
}
I am attempting to create a pom.xml file using the gradle maven plugin. It must reference a maven plugin designed for central dependency reporting. As it is right now it successfully creates the pom.xml file containing all dependencies, plugin repository info, and profile info. However if the build section is un-commented the I get an error along the lines of:
> No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.
If I try something simple like
task writeNewPom {
pom {
project {
build {
}
}
}
}
then I get the same error. It seems that gradle does not recognize build as a valid identifier. I am just hoping for a more elegant solution than manually editing xml through groovy. The only documentation on this that I can find is Gradle docs Chap 53
This is due to the fact that the project {...} closure is delegating to an instance of ModelBuilder which extends Groovy's FactoryBuilderSupport class that already defines a method named build. So instead of configuring the build property of the Maven Model object, the preexisting build method is being called.
To get around this I'd use withXml {...} to configure that portion of your pom.
pom {
project {
// other non-<build> configuration
}
}.withXml {
asNode().appendNode('build').appendNode('plugins').appendNode('plugin').with {
appendNode('groupId', 'GROUP_ID')
}
}.writeTo('pom.xml')
Here is a more detailed example:
.withXml
{
asNode().appendNode('build').appendNode('plugins').with
{
with
{
appendNode('plugin')
.with
{
appendNode('groupId', 'groupId1')
appendNode('artifactId', 'artifactId1')
appendNode('version', 'version1')
}
}
with
{
appendNode('plugin')
.with{
appendNode('groupId', 'groupId2')
appendNode('artifactId', 'artifactId2')
appendNode('version', 'version2')
}
}
}
}
.writeTo("pom.xml")

Resources