|
| 1 | +//import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar |
| 2 | +import org.gradle.api.attributes.plugin.GradlePluginApiVersion |
| 3 | + |
| 4 | +plugins { |
| 5 | + id 'java-gradle-plugin' |
| 6 | + id 'groovy' |
| 7 | + id 'idea' |
| 8 | + id 'eclipse' |
| 9 | + id 'maven-publish' |
| 10 | + alias libs.plugins.licenser |
| 11 | + alias libs.plugins.gradleutils |
| 12 | + alias libs.plugins.javadoc.links |
| 13 | + alias libs.plugins.plugin.publish |
| 14 | + //alias libs.plugins.shadow |
| 15 | +} |
| 16 | + |
| 17 | +final projectDisplayName = 'Git Version Gradle Plugin' |
| 18 | +final projectArtifactId = base.archivesName = 'gitversion-gradle' |
| 19 | +description = 'A gradle plugin for using Git Version to manage version numbers.' |
| 20 | +group = 'net.minecraftforge' |
| 21 | +version = gitversion.tagOffset |
| 22 | + |
| 23 | +println "Version: $version" |
| 24 | + |
| 25 | +java { |
| 26 | + toolchain.languageVersion = JavaLanguageVersion.of(17) |
| 27 | + withSourcesJar() |
| 28 | + withJavadocJar() |
| 29 | +} |
| 30 | + |
| 31 | +configurations { |
| 32 | + named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) { |
| 33 | + // Fixes a conflict between Git Version's shadowed SLF4J from JGit and Gradle's own loggers |
| 34 | + exclude group: 'org.slf4j', module: 'slf4j-api' |
| 35 | + } |
| 36 | + |
| 37 | + // Applies the "Gradle Plugin API Version" attribute to configuration |
| 38 | + // This was added in Gradle 7, gives consumers useful errors if they are on an old version |
| 39 | + def applyGradleVersionAttribute = { Configuration configuration -> |
| 40 | + configuration.attributes { |
| 41 | + attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(GradlePluginApiVersion, libs.versions.gradle.get())) |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + named('apiElements', applyGradleVersionAttribute) |
| 46 | + named('runtimeElements', applyGradleVersionAttribute) |
| 47 | + //named('shadowRuntimeElements', applyGradleVersionAttribute) |
| 48 | +} |
| 49 | + |
| 50 | +dependencies { |
| 51 | + // Gradle API |
| 52 | + compileOnly libs.gradle |
| 53 | + compileOnly libs.nulls |
| 54 | + |
| 55 | + runtimeOnly libs.gradleutils.plugin |
| 56 | + compileOnly libs.gradleutils.binary |
| 57 | + |
| 58 | + // Git Version |
| 59 | + implementation libs.gitver |
| 60 | + implementation libs.gson |
| 61 | +} |
| 62 | + |
| 63 | +/* |
| 64 | +// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins. |
| 65 | +// TODO [GradleUtils][GradleAPI] Remove this once they are fixed. |
| 66 | +// Publish Plugin: https://github.com/gradle/plugin-portal-requests/issues/260 |
| 67 | +// Shadow: https://github.com/GradleUp/shadow/pull/1422 |
| 68 | +afterEvaluate { project -> |
| 69 | + project.configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME) { compileOnly -> |
| 70 | + compileOnly.dependencies.remove project.dependencies.gradleApi() |
| 71 | + } |
| 72 | +} |
| 73 | + */ |
| 74 | + |
| 75 | +license { |
| 76 | + header = rootProject.file('../LICENSE-header.txt') |
| 77 | + newLine = false |
| 78 | + exclude '**/*.properties' |
| 79 | +} |
| 80 | + |
| 81 | +tasks.named('jar', Jar) { |
| 82 | + archiveClassifier = 'thin' |
| 83 | +} |
| 84 | + |
| 85 | +/* |
| 86 | +tasks.named('shadowJar', ShadowJar) { |
| 87 | + enableAutoRelocation = true |
| 88 | + archiveClassifier = null |
| 89 | + relocationPrefix = 'net.minecraftforge.gitversion.gradle.shadow' |
| 90 | +} |
| 91 | + */ |
| 92 | + |
| 93 | +tasks.withType(GroovyCompile).configureEach { |
| 94 | + groovyOptions.optimizationOptions.indy = true |
| 95 | +} |
| 96 | + |
| 97 | +tasks.withType(Javadoc).configureEach { |
| 98 | + javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion.of(24) } |
| 99 | + |
| 100 | + options { StandardJavadocDocletOptions options -> |
| 101 | + options.windowTitle = projectDisplayName + project.version |
| 102 | + options.tags 'apiNote:a:API Note:', 'implNote:a:Implementation Note:' |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +changelog { |
| 107 | + fromBase() |
| 108 | + publishAll = false |
| 109 | +} |
| 110 | + |
| 111 | +gradlePlugin { |
| 112 | + website.set gitversion.url |
| 113 | + vcsUrl.set gitversion.url + '.git' |
| 114 | + |
| 115 | + plugins { |
| 116 | + register('gitversion') { |
| 117 | + id = 'net.minecraftforge.gitversion' |
| 118 | + implementationClass = 'net.minecraftforge.gitversion.gradle.GitVersionPlugin' |
| 119 | + displayName = projectDisplayName |
| 120 | + description = project.description |
| 121 | + tags.set(['git', 'version']) |
| 122 | + } |
| 123 | + |
| 124 | + register('changelog') { |
| 125 | + id = 'net.minecraftforge.changelog' |
| 126 | + implementationClass = 'net.minecraftforge.gitversion.gradle.ChangelogPlugin' |
| 127 | + displayName = 'Git Changelog' |
| 128 | + description = 'Creates a changelog text file based on git history using GitVersion.' |
| 129 | + tags.set(['git', 'changelog']) |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +/* |
| 135 | +// Allows the thin jar to be published, but won't be considered as the java-runtime variant in the module |
| 136 | +// This forces Gradle to use the fat jar when applying the plugin |
| 137 | +(components.java as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations.runtimeElements) { |
| 138 | + skip() |
| 139 | +} |
| 140 | + */ |
| 141 | + |
| 142 | +publishing { |
| 143 | + publications.register('pluginMaven', MavenPublication) { |
| 144 | + artifactId = projectArtifactId |
| 145 | + changelog.publish it |
| 146 | + |
| 147 | + pom { pom -> |
| 148 | + name = projectDisplayName |
| 149 | + description = project.description |
| 150 | + |
| 151 | + gradleutils.pom.setGitHubDetails pom |
| 152 | + |
| 153 | + licenses { |
| 154 | + license gradleutils.pom.licenses.LGPLv2_1 |
| 155 | + } |
| 156 | + |
| 157 | + developers { |
| 158 | + developer gradleutils.pom.developers.Jonathing |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + repositories { |
| 164 | + maven gradleutils.publishingForgeMaven |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | +idea.module { downloadSources = downloadJavadoc = true } |
0 commit comments