Reputation: 21686
I am working with this example Gradle Plugin project: https://github.com/AlainODea/gradle-com.example.hello-plugin
When I run ./gradlew publishToMavenLocal it creates these files in M2_HOME:
When I run ./gradlew artifactoryPublish it logs:
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.jar
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.pom
Deploying build descriptor to: https://artifactory.example.com/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under https://artifactory.example.com/artifactory/webapp/builds/gradle-com.example.hello-plugin/1234567890123
Attempting to load the plug-in from another build.gradle:
plugins {
id 'java'
id 'com.example.hello' version '0.1-SNAPSHOT'
}
With settings.gradle:
pluginManagement {
repositories {
maven {
url 'https://artifactory.example.com/artifactory/libs-release-local-maven/'
}
}
}
Results in this error:
Plugin [id: 'com.example', version: '0.1-SNAPSHOT'] 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 'com.example.hello:com.example.hello.gradle.plugin:0.1-SNAPSHOT')
Searched in the following repositories:
maven(https://artifactory.example.com/artifactory/libs-release-local-maven/)
Gradle Central Plugin Repository
I'd like to get all of the artifacts that publishToMavenLocal creates to be published to Artifactory when I run artifactoryPublish. I am open to alternatives to artifactoryPublish if it is the wrong tool.
How do I publish Gradle plugins to Artifactory?
Upvotes: 6
Views: 9491
Reputation: 51
After giving a lot of time into this I finally got the working code for deploying custom plugin to private artifactory
artifactory {
contextUrl = 'http://localhost:8081/artifactory'
publish {
repository {
repoKey = 'libs-release-local'
username = ‘username’
password = ‘password’
}
defaults {
publications("pluginMaven")
publishArtifacts = true
publishPom = true
}
}
}
Gradle plugin dependencies
plugins {
id "java-gradle-plugin"
id "org.gradle.kotlin.kotlin-dsl" version "2.1.4"
id "com.jfrog.artifactory" version "4.27.1"
id 'org.jetbrains.kotlin.jvm' version '1.5.10'
id "maven-publish"
id "com.gradle.plugin-publish" version "0.18.0"
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Must use pluginMaven for the publications
Here is my complete build.Gradle file
plugins {
id "java-gradle-plugin"
id "org.gradle.kotlin.kotlin-dsl" version "2.1.4"
id "com.jfrog.artifactory" version "4.27.1"
id 'org.jetbrains.kotlin.jvm' version '1.5.10'
id "maven-publish"
id "com.gradle.plugin-publish" version "0.18.0"
}
group = "com.example"
version = "1.0"
repositories {
mavenCentral()
google()
}
gradlePlugin {
plugins {
simplePlugin {
id = 'com.example.plugin'
displayName = 'Code Check Plugin'
description = 'This plugin will be used for checking code convention'
implementationClass = 'com.example.plugin.CodeCheckPlugin'
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "com.android.tools.build:gradle:4.0.2"
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
}
tasks.create("checkJavaVersion").doLast {
def javaVersion = JavaVersion.current()
if (!javaVersion.isJava8()) {
throw new GradleException(
"The plugin must be published under Java 1.8 but $javaVersion is found"
)
}
}
artifactory {
contextUrl = 'http://localhost:8080/artifactory'
publish {
repository {
repoKey = 'libs-release-local'
username = 'user_name'
password = 'password'
}
defaults {
publications("pluginMaven")
publishArtifacts = true
publishPom = true
}
}
}
Upvotes: 1
Reputation: 2095
Since version 4.19 of the build-info-extractor-gradle plugin, there's an ALL_PUBLICATIONS
constant that can be used:
artifactory {
publish {
contextUrl = 'https://url.com/artifactory'
repository {
// repoKey, etc. here
}
defaults {
publications 'ALL_PUBLICATIONS'
}
}
}
Upvotes: 5
Reputation: 21686
Since you have the maven-publish plugin on, the java-gradle-plugin already declares publications for you, so you can remove this explicit publications block from your build:
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
You can then reference all automatically created publications in your artifactory publish defaults block as follows:
invokeMethod("publications", publishing.publications.names.toTypedArray())
Why not just publishing.publications.names?:
Here's the complete, corrected artifactory block:
artifactory {
setProperty("contextUrl", "https://artifactory.verafin.com/artifactory")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "libs-release-local-maven")
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", publishing.publications.names.toTypedArray())
})
})
}
Here's a complete adaptation of your build.gradle.kts solving the problem:
import groovy.lang.GroovyObject
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
buildscript {
repositories {
jcenter()
}
}
plugins {
`java-gradle-plugin`
`maven-publish`
`kotlin-dsl`
id("com.jfrog.artifactory") version "4.9.0"
kotlin("jvm") version "1.3.11"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
}
group = "com.example.hello"
version = "0.1-SNAPSHOT"
gradlePlugin {
plugins {
create("helloPlugin") {
id = "com.example.hello"
implementationClass = "com.example.HelloPlugin"
}
}
}
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom("org.junit:junit-bom:5.3.2")
}
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit:junit-bom:latest.release")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("com.natpryce:hamkrest:1.7.0.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
tasks {
withType<JavaExec> {
jvmArgs = listOf("-noverify", "-XX:TieredStopAtLevel=1")
}
withType<KotlinCompile> {
val javaVersion = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
kotlinOptions {
apiVersion = "1.3"
javaParameters = true
jvmTarget = javaVersion
languageVersion = "1.3"
}
}
withType<Test> {
@Suppress("UnstableApiUsage")
useJUnitPlatform()
}
}
artifactory {
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "libs-release-local-maven")
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", publishing.publications.names.toTypedArray())
})
})
}
Here's a log showing the successful deployment of the plugin artifact to Artifactory:
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.jar
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.pom
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/com.example.hello.gradle.plugin/0.1-SNAPSHOT/com.example.hello.gradle.plugin-0.1-SNAPSHOT.pom
Deploying build descriptor to: https://artifactory.example.com/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under https://artifactory.example.com/artifactory/webapp/builds/gradle-com.example.hello-plugin/1234567890123
Upvotes: 9