Gradle maven-publish - custom local maven repository location - maven

I am using:
apply plugin: "maven-publish"
I am trying to install my artifact in $buildDir/repo instead of ~/.m2/repository.
I have tried this:
publishing {
repositories {
maven {
url "$buildDir/repo"
}
}
}
and this:
-Dmvn.repo.local=build/repo
But those are ignored.
I would like to avoid using the settings.xml to set that, is it possible?

Related

How to use snapshot repository for openapi gradle plugin?

I would like to use snapshot repository for open API generator in Gradle. However it still cannot find the plugin.
settings.gradle.kts
pluginManagement {
repositories {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
gradlePluginPortal()
}
}
build.gradle.kts
plugins {
id("org.openapi.generator") version "6.3.0-SNAPSHOT"
}
Error:
Plugin [id: 'org.openapi.generator', version: '6.3.0-SNAPSHOT'] was not found in any of the following sources:
It seems like it is still pointing to the gradle plugin portal.
The URL of the snapshot is
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-gradle-plugin/6.3.0-SNAPSHOT
You need to update groupId (org.openapitools) and artifactid (openapi-generator-gradle-plugin)

Gradle apply plugin vs plugins

I have a simple plugin with greet task doing some 'Hello World' print.
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'maven-publish'
}
group = 'standalone.plugin2.greeting'
version = '1.0'
gradlePlugin {
plugins {
greeting {
id = 'standalone.plugin2.greeting'
implementationClass = 'standalone.plugin2.StandalonePlugin2Plugin'
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'standalone.plugin2.greeting'
version = '1.0'
from components.java
}
}
}
Now, I have runner application to just run the greet task
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'standalone.plugin2.greeting:standalone-plugin2:1.0'
}
}
apply plugin: 'standalone.plugin2.greeting'
With apply plugin natation it works OK, but when I use plugins notation instead like this:
plugins {
id 'standalone.plugin2.greeting' version '1.0'
}
it doesn't work.
The error message is:
* What went wrong:
Plugin [id: 'standalone.plugin2.greeting', version: '1.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'standalone.plugin2.greeting:standalone.plugin2.greeting.gradle.plugin:1.0')
Searched in the following repositories:
Gradle Central Plugin Repository
What is the difference? According to documentation apply plugin is old and should not be used.
Before the introduction of the plugins block, plugin dependencies had to be resolved in the same way as regular project dependencies using a combination of repositories and dependencies. Since they need to be resolved before running the actual build script, they need to be defined in the special buildscript block:
buildscript {
repositories {
// define repositories for build script dependencies
}
dependencies {
// define build script dependencies (a.k.a. plugins)
}
}
repositories {
// define repositories for regular project dependencies
}
dependencies {
// define regular project dependencies
}
Once the dependencies were resolved, they could be applied using apply plugin:.
By default, the new plugins block just resolves the plugins from the Gradle Plugin Repository. This is a regular Maven repository, so it can be used using the old way, too:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
In your case, the plugin only exists in mavenLocal, so the plugins block cannot resolve it, as it only looks into the Gradle Central Plugin Repository. You may use the pluginManagement block to resolve plugins from custom repositories.
As described in the article linked above, it is necessary to create a link between the plugin identifier (used inside the plugins block) and the Maven coordinates that provide the respective plugin. To create this link a marker artifact following a specific convention must be published. The Gradle Plugin Development Plugin automatically publishes this marker artifact if used in combination with the Maven Publish Plugin.

gradle archiva integration copy jar from build to archiva repository

I am integrating gradle to archiva.I was able to build the jar of the project successfully , but craeting inside build/libs.
I want to add this jar to my archiva repository internal after build. please guide me
my archiva repo
http://localhost:8080/repository/internal/
See Gradle docs:
Chapter 34. Maven Publishing - describes how to use 'maven-publish' gradle plugin to define publications and repositories.
34.4. Performing a publish - contains full example of additions to build.gradle:
apply plugin: 'java'
apply plugin: 'maven-publish'
group = 'org.gradle.sample'
version = '1.0'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
publishing {
repositories {
maven {
url "http://localhost:8080/repository/internal/"
credentials {
username repoUser
password repoPassword
}
}
}
}
Add credentials {} section if you need to supply username/password for repository. repoUser and repoPassword are variables defined somewhere else. For example, apply gradle-properties-plugin and define these variables in gradle-local.properties:
repoUser=jsmith
repoPassword=secret
Make sure not to commit this file into source code repository.

How to access local repo from gradle

I am trying to build a Java project using Gradle. I have some dependencies (jars) that are in a location of the type: http://internal_domain.location.local:9000/artifacts/repo
How do I specify this in the build.gradle file? Is it under repositories {}?
In the gradle documentation I came across this but doing something similar does not work for me:
repositories {
ivy {
url "http://repo.mycompany.com/repo"
resolve.dynamicMode = true
}
}
Assuming your local repo is a maven repo
repositories {
maven {
// Look for POMs and artifacts, such as JARs, here
url "http://repo2.mycompany.com/maven2"
// Look for artifacts here if not found at the above location
artifactUrls "http://repo.mycompany.com/jars"
artifactUrls "http://repo.mycompany.com/jars2"
}
}
Local Archive Gradle

Publishing artifact from gradle project to bintray (maven repository)

I have configured Gradle to publish project artifact using new Maven Publisher Plugin, unfortunately this plugin has problem with dependency in generated pom.xml - dependencies has scope runtime instead of compile.
My configuration is like this:
apply plugin: 'maven-publish'
publishing {
publications {
mavenCustom(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "https://api.bintray.com/maven/codearte/public/fairyland"
credentials {
username = bintrayUser
password = bintrayKey
}
}
}
}
Publishing was simple with one command:
gradle publish
How to achieve this in old (working) way? Is possible to automate project taging when project is released?
Ok, I figured it out:
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
name = 'Codearte Public Repository'
repository(id: 'codearte-repository', url: 'https://api.bintray.com/maven/codearte/public/fairyland'){
authentication(userName: bintrayUser, password: bintrayKey)
}
}
}
Uploading with command:
gradle uploadArchives
The fact that all POM dependencies have runtime scope is a known limitation of the new, incubating maven-publish plugin. Until this gets fixed, you can either fix it up yourself by using the publication.pom.withXml hook, or fall back to the maven plugin. Both plugins are documented in the Gradle User Guide.
Tagging is an entirely different question. You can either use one of the third-party Gradle SCM plugins or call out to a command line tool (e.g. with an Exec task).

Resources