Gradle - globally define plugins repository proxy-cache for all projects - gradle

I need to globally set the plugin repositories for all Gradle projects. There is a way of doing that by adding the below section in settings.gradle file:
pluginManagement {
repositories {
maven {
url 'https://artifactory.mycompany.org/artifactory/gradle-plugins/'
credentials {
username = 'some-user'
password = 'some-password'
}
}
}
}
However, when I put this file in ~/.gradle/settings.gradle, it doesn't seem to be working. I don't want to add such settings.gradle file in each project due to corporate reasons.
Is there a way of telling Gradle globally where to fetch all of the plugins?

Related

how to set archiveBaseName for local .m2 repository

I'm trying to upgrade a dependency to a project that will ultimately become a dependency to my project. I've made the upgrade and I want to test it locally before I put it out on the repo to be used. I'm learning Gradle and a few Google searches showed me how to add the project to the settings.gradle file. But the dependency project uses aliases for their dependencies (see build.gradle below).
settings.gradle
include ':TransportImpl'
Changed to:
include ':TransportImpl', ':jeromq'
project(':jeromq').projectDir = new File("../zeromq/jeromq")
build.gradle
//project.ext.set("JEROMQ", 'THIRD-PARTY:jeromq:0.4.2')
project.ext.set("JEROMQ", ':jeromq')
If I uncomment the original line (shown commented above), because that apk is in the repo it gets recognized. I'm guessing that this only works for external libraries.
Other things I have tried:
//project.ext.set("JEROMQ", 'C:/Users/username/.m2/repository/THIRD_PARTY/jeromq/0.5.1-SNAPSHOT/jeromq-0.5.1-SNAPSHOT-jeromq.jar')
//project.ext.set("JEROMQ", 'C:\\Users\\username\\.m2\\repository\\THIRD_PARTY\\jeromq\\0.5.1\\jeromq-0.5.1-jeromq.jar')
//implementation filetree(dir: 'C:\\Users\\username\\.m2\\repository\\THIRD_PARTY\\jeromq\\0.5.1', include:['jeromq-0.5.1-jeromq.jar'])
Can anyone give me a tip on how I can assign a variable that points to the local repository and use that variable to set an archiveBaseName?
New Information:
gradle.build for our jeromq project
apply plugin : 'maven'
apply plugin : 'maven-publish'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
// Nexus paths
nexusUrl='https://nexus.path'
Releases='/Private_Releases'
nexusUsername = project.findProperty("nexusUsername") ?: (System.getenv("NEXUS_USERNAME") ?: "user_name"
nexusPassword = project.findProperty("nexusPassword") ?: (System.getenv("NEXUS_PASSWORD") ?: "password")
// Project versions
jeromqVersion = "0.5.1-SNAPSHOT"
}
allprojects {
// Read only repositories for dependencies; this should never be used to publish
repositories {
mavenCentral()
jcenter()
}
}
The project that uses it as a dependency finds it using the following from its build.gradle file:
// Create aliases for dependencies
project.ext.set("EASY_MOCK", 'Test:easymock:3.5.1')
project.ext.set("OBJENESIS", 'Test:objenesis:2.6')
// **************** HERE ***************************
// THIRD-PARTY is configured to look on the nexus server
project.ext.set("JEROMQ", 'THIRD-PARTY:jeromq:0.4.2') ... or 0.5.1 or 0.5.1-SNAPSHOT ...
allprojects {
// Read only repositories for dependencies; this should never be used to publish
repositories {
mavenCentral()
mavenLocal()
// maven {
// // trying to add my local repo,
// // BUT this still does not change where THIRD-PARTY is pointing to
// url 'file://C:/Users/me/.m2/repository/THIRD_PARTY/jeromq/0.5.1-SNAPSHOT/jeromq-0.5.1-SNAPSHOT-jeromq.jar'
// }
maven {
name 'ReleasesName'
url "$nexusUrl$ReleasesName
}
}
maven {
name 'ReleasesNameSnapshots'
url "$nexusUrl$ReleasesNameSnapshots"
credentials {
username "${rootProject.ext.nexusReadOnlyUsername}"
password "${rootProject.ext.nexusReadOnlyPassword}"
}
}
jcenter {
url "https://jcenter.bintray.com/"
}
}
The only reason I need the alias for that dependency is because it is used in other places.
I'm not entirely sure what you are asking, but I think what you are trying is completely off.
The build you are trying to include is a Maven build, not a Gradle build, so it is unlikely you can simply treat it as it were a Gradle build.
And even if it were a Gradle build, including it like you did would not be the right way. How you tried it is for including multiple projects of a multi-project build, not including external libraries.
If it were a Gradle build, you would use a composite build, which effectively replaces a declared binary dependency by the build output of a "sub-build". But afair this only works cleanly with a Gradle build.
Why don't you simply mvn install your modified jeromq version, add mavenLocal() to your dependencies and depend on that just installed version? That would be the usual way for locally testing new Maven built dependencies.

Gradle repositories in Gradle settings instead of build?

In Maven, you can store the list of repositories in settings.xml, which means each developer can have his own settings (when you are inside a company, you will use the local Nexus as a mirror, but when outside, you will use Maven Central).
How do you do that with Gradle ?
You can use a gradle init script for that. these init scripts can live in the ~/.gradle/init.d/ folder. Having on (e.g. default-repos.gradle) with adding default repositories can look like this:
allprojects {
repositories {
maven {
url = 'http://nexus.local.org'
}
}
}

Setting up Artifactory in gradle global

currently I have a project which is deploying artifacts in our artifactory. For that Project everything is setted up perfect and it works.
I just wonderd if there is a possibility to set up the whole artifactory configuration global in gradle, so that I don't have to write the artifactory {...} stuff for each project.
You can maintain a file lets say build_dependency.gradle and define the task for all project
allprojects
{
//task common for all the project
}
subprojects
{
//task for subprojects
}
or specify the type of project e.g ext.warProject = 1 in dependency file and refer it in build_dependency.gradle as
if(project.hasProperty('warProject '))
{
//task here
}
and use this file in build.gradle like apply from: "$rootDir/path_to_file/build_dependency.gradle"
"$rootDir/path_to_dependenccy_file"`
You could simply write your own Gradle plugin that would be responsible for:
applying the artifactory plugin and other related plugin(s) like maven-publish
provide default values for the artifactory extension properties , like contextUrl, repoKey, credentials, etc...
Then your different projects will just have to apply your custom plugin, and provide only the project-specific configuration (configuration of the artefact to be published, for example, in publishing extension)
EDIT there are other ways to implement that, but it depends on what you mean by "global in gradle":
global to your own computer? then you could create a User InitScript that would contain the artifactory plugin configuration part
global to your team/company ? then you could need to implement a custom plugin, and maybe include this plugin into a custom gradle wrapper distribution (see example here
EDIT2 If you just want to set the artifactory plugin configuration of different sub-project of a same multi-project build, then the simpliest solution would be to define this configuration in the subprojects block of the root project build script:
subprojects {
apply plugin: "com.jfrog.artifactory"
artifactory {
publish {
contextUrl = '<repo url>'
repository {
repoKey = "<repo name>"
username = "user"
password = "pass"
}
}
}
}

How do I preconfigure Gradle Plugin Repository?

I want to use new fancy plugin { id: ''} syntax in Gradle with my custom in-house plugins that are stored in company's Artifacotry. In order to do this I can set maven repository for Gradle Plugin Repostiory in settings.gradle only.
I want to set this globally in my custom Gradle package that would be downloaded using Gradle wrapper. I can define globally dependencies repository and buildscript dependendencies repository in $GRADLE/init.d/repositories.gradle script, but I can not do it for Gradle Plugin Registry because it is required to be placed in settings.gradle.
How can I achieve this?
You can accomplish this using the settingsEvaluated method from the Gradle API.
Put the following in an init script.
def ENTERPRISE_REPOSITORY_URL = "https://repo.gradle.org/gradle/repo"
settingsEvaluated { setting ->
setting.pluginManagement.repositories {
// Remove all repositories not pointing to the enterprise repository url
all { ArtifactRepository repo ->
if (!(repo instanceof MavenArtifactRepository) ||
repo.url.toString() != ENTERPRISE_REPOSITORY_URL) {
project.logger.lifecycle "Repository ${repo.url} removed. Only
$ENTERPRISE_REPOSITORY_URL is allowed"
remove repo
}
}
// add the enterprise repository
maven {
name "STANDARD_ENTERPRISE_REPO"
url ENTERPRISE_REPOSITORY_URL
}
}
}

Setting POM version for upload archive in Gradle build

I am using Gradle to build my own Android Libraries. I put this libraries into a gradle multi project.
Root Project
Lib A
Lib B
and so on.
I am trying to upload the created aar files into my local maven repo (.m2 directory)
I am using the following commands in my gradle file of the Root Project
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenLocal().url)
pom.groupId = rootProject.group
pom.artifactId = project.name
pom.version = project.version
}
}
}
everything works fine except the settings for the project.version. Where can I define the value for every single subproject?
Regards
Michael
Try checking out Gradle-Fury at https://github.com/gradle-fury/gradle-fury
Essentially, set the pom.version and various other settings in gradle.properties, add a few apply from throughout the build.gradle files and you're set. Definitely works with direct publication to sonatype oss/central.
These settings can be overridden on a per module basis by adding a gradle.properties file in each module that you need to override the parent's settings from.
declaimer: i'm one of the authors

Resources