Skip to content

Instantly share code, notes, and snippets.

@asardaes
Last active April 15, 2023 12:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asardaes/6abf1fede590257e3448e59fd0d0af2a to your computer and use it in GitHub Desktop.
Save asardaes/6abf1fede590257e3448e59fd0d0af2a to your computer and use it in GitHub Desktop.
Publishing a Gradle precompiled script plugin to a custom repository
Gradle plugins require a marker:
https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
Markers aren't published for precompiled scripts using groovy-gradle-plugin :(
https://github.com/gradle/gradle/issues/15190
The plugin_marker module creates the marker that Gradle needs to find the plugin and also publishes it,
see https://stackoverflow.com/a/60798021/5793905
Assuming all gradle modules have the same group with a folder structure like:
- build.gradle
--> plugin/
----> build.gradle
----> src/main/groovy/foo.gradle
----> marker/
------> build.gradle
Replace underscores with forward slashes in file names below.
allprojects {
group "com.foo.bar"
version "0.0.0-SNAPSHOT"
afterEvaluate {
if (project.plugins.hasPlugin("groovy-gradle-plugin")) {
// names of META-INF/gradle-plugins/*.properties files in the jars don't include group for some reason... Gradle needs that convention
pluginDescriptors {
afterEvaluate {
declarations.get().each { PluginDeclaration declaration ->
declaration.id = "${project.group}.${declaration.id}"
}
}
}
}
}
}
plugins {
id "groovy-gradle-plugin"
}
/* optional
dependencies {
api ...
}
*/
plugins {
id "java-library"
id "maven-publish"
}
group = "${group}.${project.parent.name}"
dependencies {
implementation project(":${project.parent.name}")
}
publishing {
repositories {
maven {
url "foo"
credentials {
username = "bar"
password = "baz"
}
}
}
publications {
pluginMarker(MavenPublication) {
artifactId = "${project.group}.gradle.plugin"
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
dependencies {
project.configurations.each { conf ->
conf.dependencies.each { dep ->
dependency {
groupId dep.group
artifactId dep.name
version dep.version
}
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment