Last active
April 15, 2023 12:33
-
-
Save asardaes/6abf1fede590257e3448e59fd0d0af2a to your computer and use it in GitHub Desktop.
Publishing a Gradle precompiled script plugin to a custom repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id "groovy-gradle-plugin" | |
} | |
/* optional | |
dependencies { | |
api ... | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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