Skip to content

Commit 7ea8ec0

Browse files
authored
Modernize buildscript, Gradle 9, GradleUtils 3 (#1)
No changes have been made to the plugin itself
1 parent 9400f1a commit 7ea8ec0

File tree

6 files changed

+224
-121
lines changed

6 files changed

+224
-121
lines changed

.gitignore

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
/.gradle/
2-
/.classpath
3-
/.project
4-
/.settings/
5-
/bin/
6-
/test/
7-
/build/
8-
/repo/
1+
# gradle
2+
.gradle
3+
build
4+
repo
5+
6+
# eclipse
7+
.settings
8+
.metadata
9+
.classpath
10+
.project
11+
bin
12+
13+
# intellij
14+
out
15+
*.idea
16+
*.iml
17+

README.md

Lines changed: 91 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,100 @@
11
# GradleJarSigner
2-
This is a simple gradle plugin that uses ant to execute the [jarsigner](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jarsigner.html) utility. This embeds a signature in the jar file that can be used to verify its contents haven't been modified and came from a specific source. This does NOT create an external GPG signature file. The built in signing plugin does that.
32

4-
I made this because I got tired of having to configure everything manually for this in every project, and I wanted to have a simple way of signing data in Github Actions.
3+
This is a simple gradle plugin that uses ant to execute
4+
the [jarsigner](https://docs.oracle.com/javase/8/docs/technotes/tools/windows/jarsigner.html)
5+
utility. This embeds a signature in the jar file that can be used to verify its
6+
contents haven't been modified and came from a specific source.
7+
8+
I made this because I got tired of having to configure everything manually for
9+
this in every project, and I wanted to have a simple way of signing data in
10+
GitHub Actions.
11+
12+
> [!NOTE]
13+
> This does **not** create an external GPG signature file. The built-in
14+
> [signing](https://docs.gradle.org/current/userguide/publishing_signing.html)
15+
> plugin does that.
516
617
### Usage
7-
I haven't published this to the gradle plugin portal yet so until I do you need to have this in your settings.gradle.
8-
9-
pluginManagement {
10-
repositories {
11-
gradlePluginPortal()
12-
maven { url = 'https://maven.minecraftforge.net/' }
13-
}
14-
}
15-
And in your build.gradle
16-
17-
plugins {
18-
id 'net.minecraftforge.gradlejarsigner'
19-
}
20-
This will add a extension name 'jarSigner' to your project where you can configure the signing information, or you can configure it in each signing task.
21-
22-
jarSigner {
23-
alias = 'key_name'
24-
storePass = 'store_password'
25-
keyPass = 'key_password'
26-
keyStoreFile = file('keystore_file')
27-
// Or you can specify the keystore file as a base64 encoded string.
28-
// This is mainly meant to allow it to be passed in via a Github Action Secret
29-
keyStoreData = 'aGVsbG8='
30-
}
31-
32-
Then to sign the `jar` task you can do `jarSigner.sign(jar)`, this works for any Jar or Zip task.
33-
You can also configure the task itself to specify any of the information set in the global config as well as any filters on the data you wish to sign.
34-
35-
jarSigner.sign(jar) {
36-
alias = 'key_name'
37-
storePass = 'store_password'
38-
keyPass = 'key_password'
39-
keyStoreFile = file('keystore_file')
40-
exclude 'unsigned.txt'
41-
}
42-
43-
### Github Secrets
44-
A large motivation for this was wanting to use Github Actions and still be able to sign my built files. Github does not allow you to have files as [secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) just strings and the workarounds I found involved committing a encrypted form of your keystore to your repo and then decrypting it during an Action. Instead I decided to allow you to specify the keystore file as a base64 encoded string which can be used as a Secret.
45-
46-
You can either manually configure the information by pulling the secrets yourself, or I added a simple helper `jarSigner.autoDetect()` which which search the following locations in order:
47-
48-
if (prefix != null) {
49-
project.findProperty(prefix + '.' + prop)
50-
System.getenv(prefix + '.' + prop)
51-
}
52-
project.findProperty(prop)
53-
System.getenv(prop)
54-
`prefix` defaults to `project.name` you can override by calling `jarSigner.autoDetect('prefix')`
18+
19+
You can apply the plugin by declaring it in your `build.gradle` file.
20+
21+
```groovy
22+
plugins {
23+
id 'net.minecraftforge.gradlejarsigner'
24+
}
25+
```
26+
27+
This will add an extension named `jarSigner` to your project where you can
28+
configure the signing information.
29+
30+
```groovy
31+
jarSigner {
32+
alias = 'key_name'
33+
storePass = 'store_password'
34+
keyPass = 'key_password'
35+
keyStoreFile = file('keystore_file')
36+
// Or you can specify the keystore file as a base64 encoded string.
37+
// This is mainly meant to allow it to be passed in via a Github Action Secret
38+
keyStoreData = 'aGVsbG8='
39+
}
40+
```
41+
42+
Then, to sign the `jar` task, you can do `jarSigner.sign(jar)`. This works for
43+
any Jar or Zip task.
44+
45+
You can also configure the task itself to specify any of the information set in
46+
the global config as well as any filters on the data you wish to sign.
47+
48+
```groovy
49+
jarSigner.sign(jar) {
50+
alias = 'key_name'
51+
storePass = 'store_password'
52+
keyPass = 'key_password'
53+
keyStoreFile = file('keystore_file')
54+
exclude 'unsigned.txt'
55+
}
56+
```
57+
58+
### GitHub Secrets
59+
60+
A large motivation for this was wanting to use GitHub Actions and still be able
61+
to sign my built files. GitHub does not allow you to have files as
62+
[secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets),
63+
just strings. The workarounds I found involved committing an encrypted form of
64+
your keystore to your repo and then decrypting it during an Action. I instead
65+
decided to allow you to specify the keystore file as a base64 encoded string
66+
which can be used as a secret.
67+
68+
You can either manually configure the information by pulling the secrets
69+
yourself, or I added a simple helper `jarSigner.autoDetect()` which which search
70+
the following locations in order:
71+
72+
```groovy
73+
if (prefix != null) {
74+
project.findProperty(prefix + '.' + prop)
75+
System.getenv(prefix + '.' + prop)
76+
}
77+
project.findProperty(prop)
78+
System.getenv(prop)
79+
```
80+
81+
`prefix` defaults to `project.name`. You can override this by calling
82+
`jarSigner.autoDetect('prefix')`.
5583

5684
For the following properties:
5785

58-
jarSigner {
59-
alias = 'SIGN_KEY_ALIAS'
60-
keyPass = 'SIGN_KEY_PASSWORD'
61-
storePass = 'SIGN_KEYSTORE_PASSWORD'
62-
keyStoreData = 'SIGN_KEYSTORE_DATA'
63-
}
86+
```groovy
87+
jarSigner {
88+
alias = 'SIGN_KEY_ALIAS'
89+
keyPass = 'SIGN_KEY_PASSWORD'
90+
storePass = 'SIGN_KEYSTORE_PASSWORD'
91+
keyStoreData = 'SIGN_KEYSTORE_DATA'
92+
}
93+
```
6494

6595
### Conclusion
66-
I'm sure there are improvements that could be made, but it works good enough for me so this is where I'm at. If you have suggestions for improvements feel free to submit them. But the point of this plugin is to be small, simple, and single purpose.
96+
97+
I'm sure there are improvements that could be made, but it works good enough for
98+
me so this is where I'm at. If you have suggestions for improvements feel free
99+
to submit them. But the point of this plugin is to be small, simple, and single
100+
purpose.

build.gradle

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,118 @@
1+
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
2+
13
plugins {
2-
id 'org.cadixdev.licenser' version '0.6.1'
3-
id 'maven-publish'
4-
id 'java'
54
id 'java-gradle-plugin'
5+
id 'idea'
66
id 'eclipse'
7-
id 'net.minecraftforge.gradleutils' version '2.2.0'
8-
id 'com.gradle.plugin-publish' version '1.2.1'
9-
}
10-
11-
repositories {
12-
mavenCentral()
7+
id 'maven-publish'
8+
alias libs.plugins.licenser
9+
alias libs.plugins.gradleutils
10+
alias libs.plugins.gitversion
11+
alias libs.plugins.changelog
12+
alias libs.plugins.plugin.publish
1313
}
1414

15+
final projectDisplayName = 'Gradle Jar Signer Plugin'
16+
final projectArtifactId = base.archivesName = 'gradlejarsigner'
17+
final projectVendor = 'Forge Development LLC'
18+
description = 'Wrapper for Ant signjar, allowing proper task caching'
1519
group = 'net.minecraftforge'
16-
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
17-
java.withSourcesJar()
20+
version = gitversion.tagOffset
1821

19-
license {
20-
header project.file('LICENSE-header.txt')
21-
newLine false
22-
}
22+
println "Version: $version"
2323

24-
version = gradleutils.tagOffsetVersion
25-
println('Version: ' + version)
24+
java {
25+
toolchain.languageVersion = JavaLanguageVersion.of(8)
26+
withSourcesJar()
27+
//withJavadocJar()
28+
}
2629

27-
gradlePlugin {
28-
website = 'https://github.com/MinecraftForge/GradleJarSigner'
29-
vcsUrl = 'https://github.com/MinecraftForge/GradleJarSigner.git'
30-
plugins {
31-
gradlejarsigner {
32-
id = 'net.minecraftforge.gradlejarsigner'
33-
implementationClass = 'net.minecraftforge.gradlejarsigner.GradleJarSignerPlugin'
34-
displayName = 'Gradle Jar Signer'
35-
description = 'Wrapper for Ant signjar, allowing proper task caching'
36-
tags.set(['signing', 'java', 'signjar'])
30+
configurations {
31+
// Applies the "Gradle Plugin API Version" attribute to configuration
32+
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
33+
def applyGradleVersionAttribute = { Configuration configuration ->
34+
configuration.attributes {
35+
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(GradlePluginApiVersion, libs.versions.gradle.get()))
3736
}
3837
}
38+
39+
named('runtimeElements', applyGradleVersionAttribute)
3940
}
4041

4142
dependencies {
43+
// Static Analysis
44+
compileOnly libs.nulls
45+
46+
// Gradle API
47+
compileOnly libs.gradle
4248
}
4349

44-
compileJava {
50+
license {
51+
header = rootProject.file('LICENSE-header.txt')
52+
newLine = false
53+
exclude '**/*.properties'
54+
}
55+
56+
tasks.withType(JavaCompile).configureEach {
4557
options.encoding = 'UTF-8'
4658
}
4759

48-
jar {
60+
tasks.named('jar', Jar) {
4961
manifest {
5062
attributes([
51-
'Specification-Title': 'GradleJarSigner',
52-
'Specification-Vendor': 'Forge Development LLC',
53-
'Specification-Version': gradleutils.gitInfo.tag,
54-
'Implementation-Title': 'GradleJarSigner',
55-
'Implementation-Vendor': 'Forge Development LLC',
63+
'Specification-Title' : projectDisplayName,
64+
'Specification-Vendor' : projectVendor,
65+
'Specification-Version' : gitversion.info.tag,
66+
'Implementation-Title' : projectDisplayName,
67+
'Implementation-Vendor' : projectVendor,
5668
'Implementation-Version': project.version
57-
] as LinkedHashMap, 'net/minecraftforge/gradlejarsigner/')
69+
], 'net/minecraftforge/gradlejarsigner/')
5870
}
5971
}
6072

6173
changelog {
62-
fromTag '1.0'
74+
from '1.0'
6375
publishAll = false
6476
}
6577

78+
gradlePlugin {
79+
website = gitversion.url
80+
vcsUrl = gitversion.url + '.git'
81+
82+
plugins.register('gradlejarsigner') {
83+
id = 'net.minecraftforge.gradlejarsigner'
84+
implementationClass = 'net.minecraftforge.gradlejarsigner.GradleJarSignerPlugin'
85+
displayName = projectDisplayName
86+
description = project.description
87+
tags = ['signing', 'java', 'signjar']
88+
}
89+
}
90+
6691
publishing {
92+
repositories {
93+
maven gradleutils.publishingForgeMaven
94+
}
95+
6796
publications.register('pluginMaven', MavenPublication) {
97+
artifactId = projectArtifactId
6898
changelog.publish(it)
69-
pom {
70-
packaging = 'jar'
71-
description = 'Gradle Jar Signer Plugin'
72-
url = 'https://github.com/MinecraftForge/GradleJarSigner'
7399

74-
gradleutils.pom.setGitHubDetails(pom, 'GradleJarSigner')
100+
pom { pom ->
101+
name = projectDisplayName
102+
description = project.description
103+
104+
gradleutils.pom.addRemoteDetails(pom)
75105

76-
license gradleutils.pom.licenses.LGPLv2_1
106+
licenses {
107+
license gradleutils.pom.licenses.LGPLv2_1
108+
}
77109

78110
developers {
79-
developer gradleutils.pom.Developers.LexManos
111+
developer gradleutils.pom.developers.LexManos
80112
}
81113
}
82114
}
83-
repositories {
84-
maven gradleutils.publishingForgeMaven
85-
}
86115
}
116+
117+
idea.module { downloadSources = downloadJavadoc = true }
118+
eclipse.classpath { downloadSources = downloadJavadoc = true }

gradle.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
org.gradle.caching=true
2+
org.gradle.parallel=true
3+
org.gradle.configureondemand=true
4+
5+
org.gradle.configuration-cache=true
6+
org.gradle.configuration-cache.parallel=true
7+
org.gradle.configuration-cache.problems=warn
8+
9+
systemProp.org.gradle.unsafe.suppress-gradle-api=true

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)