-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
246 lines (215 loc) · 7.69 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'maven-publish'
id 'org.cadixdev.licenser' version '0.6.1'
id 'com.gradle.plugin-publish' version '1.1.0'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
withSourcesJar()
}
sourceSets {
immaculate
}
group 'net.neoforged.gradleutils'
version '4.0.0'
repositories {
mavenCentral()
gradlePluginPortal()
}
// Immaculate runs on J17
tasks.named('compileImmaculateJava', JavaCompile).configure {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.named('compileImmaculateGroovy', GroovyCompile).configure {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
if (System.getenv('GPP_KEY')) {
project.ext {
set('gradle.publish.key', System.getenv('GPP_KEY'))
set('gradle.publish.secret', System.getenv('GPP_SECRET'))
}
}
configurations {
immaculateImplementation.extendsFrom(api)
}
dependencies {
api 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
api 'io.github.gradle-nexus:publish-plugin:1.3.0'
api("net.neoforged:groovydslimprover:${gdi_version}") {
capabilities {
requireCapability 'net.neoforged:groovydslimprover-base'
}
}
immaculateImplementation(gradleApi())
immaculateImplementation "dev.lukebemish.immaculate:dev.lukebemish.immaculate.gradle.plugin:0.1.6"
}
sourceSets {
actionsTemplate
}
final actionsTemplateZip = tasks.register('createActionsTemplateZip', Zip) {
from(sourceSets.actionsTemplate.output)
archiveFileName.set('.github-workflows.zip')
destinationDirectory.set(layout.buildDirectory.dir('template'))
}
tasks.named(sourceSets.main.processResourcesTaskName, Copy) {
from(actionsTemplateZip)
}
tasks.named('jar', Jar) {
try {
final ByteArrayOutputStream bos = new ByteArrayOutputStream()
project.exec {
commandLine('git', 'rev-parse', 'HEAD')
standardOutput(bos)
}.rethrowFailure().assertNormalExitValue()
final gitCommit = new String(bos.toByteArray())
// Store the git commit as the Implementation-Version of the tasks package
// TODO - re-evaluate: find a better way of storing this sha for use in template generation
manifest.attributes([
'Implementation-Version': gitCommit
], 'net/neoforged/gradleutils/tasks/')
} catch (Exception ex) {
throw new IllegalStateException("Failed to determine the latest commit hash; check if 'git' is on the PATH", ex)
}
}
license {
header(file('HEADER'))
skipExistingHeaders = true // Ignore existing license headers on files
exclude 'formatter-config.xml'
}
// Disable the license tasks for the template files
["checkLicenseActionsTemplate", "updateLicenseActionsTemplate"].each {
tasks.named(it) {
enabled = false
}
}
gradlePlugin {
website = 'https://github.com/neoforged/GradleUtils'
vcsUrl = 'https://github.com/neoforged/GradleUtils.git'
plugins {
gradleutils {
id = 'net.neoforged.gradleutils'
displayName = 'GradleUtils'
description = 'A plugin with different utilities for NeoForged projects. Includes tag-based versioning and changelog generation'
tags.set(['versioning', 'changelog'])
implementationClass = 'net.neoforged.gradleutils.GradleUtilsPlugin'
}
gradleutilsImmaculate {
id = 'net.neoforged.gradleutils.immaculate'
displayName = 'GradleUtils Immaculate'
description = 'A plugin that configures Immaculate on projects'
tags.set(['immaculate'])
implementationClass = 'net.neoforged.gradleutils.immaculate.ImmaculatePlugin'
}
}
}
final changelogTask = tasks.register('changelog', GenerateChangelogTask) {
it.description = 'Generates a commit changelog using the git CLI command'
it.changelogFile.set(layout.buildDirectory.file('changelog.txt'))
}
tasks.named('jar', Jar) {
from(sourceSets.immaculate.output)
}
tasks.named('assemble') {
it.dependsOn changelogTask
}
tasks.named('publishPlugins') {
it.enabled = !project.version.toString().endsWith('-SNAPSHOT')
}
publishing {
publications {
pluginMaven(MavenPublication) { mavenPublication ->
artifact(changelogTask) {
classifier = 'changelog'
extension = 'txt'
}
pom {
name = 'Gradle Utils'
description = 'Gradle buildscript utility library for NeoForged projects'
url = 'https://github.com/neoforged/GradleUtils'
scm {
url = 'https://github.com/neoforged/GradleUtils'
connection = 'https://github.com/neoforged/GradleUtils.git'
developerConnection = 'scm:git:[email protected]:NeoForged/GradleUtils.git'
}
issueManagement {
system = 'github'
url = 'https://github.com/neoforged/GradleUtils/issues'
}
organization {
name = 'NeoForged'
url = 'https://github.com/neoforged'
}
licenses {
license {
name = 'LGPLv2.1'
url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt'
}
}
}
}
}
repositories {
maven {
name 'forge'
if (System.env.MAVEN_USER && System.env.MAVEN_PASSWORD) {
def publishingEndpoint = System.env.MAVEN_URL_RELEASE ?: 'https://maven.neoforged.net/releases'
if (project.version.toString().endsWith('-SNAPSHOT')) {
url System.env.MAVEN_URL_SNAPSHOTS ?: 'https://maven.neoforged.net/snapshots'
} else {
url publishingEndpoint
}
authentication {
basic(BasicAuthentication)
}
credentials {
username = System.env.MAVEN_USER
password = System.env.MAVEN_PASSWORD
}
} else {
url 'repo'
}
}
}
}
final versionProvider = providers.provider { project.version?.toString() }
tasks.register("configureGitHubActions", ConfigureActions) {
version.set(versionProvider)
}
abstract class ConfigureActions extends DefaultTask {
@Input
abstract Property<String> getVersion()
@TaskAction
void doAction() {
final versionString = version.get()
new File(System.getenv('GITHUB_OUTPUT')) << "version=$versionString"
}
}
abstract class GenerateChangelogTask extends DefaultTask {
@OutputFile
abstract RegularFileProperty getChangelogFile()
@javax.inject.Inject // This might look like a compile error in IDE, but it actually compiles okay
abstract ExecOperations getExecOperations()
@TaskAction
void generate() {
try {
changelogFile.get().asFile.withOutputStream { output ->
execOperations.exec { ExecSpec spec ->
// TODO: limit to last reachable tag?
spec.commandLine('git', 'log', '--no-show-signature', '--no-color',
'--pretty=%h% (describe:tags=true:abbrev) (%aN) %s')
spec.standardOutput(output)
}.assertNormalExitValue().rethrowFailure()
}
} catch (Exception e) {
throw new IllegalStateException("Failed to generate changelog; check if 'git' is on the PATH", e)
}
}
}