Skip to content

Commit c69bcc3

Browse files
authored
Migrate to Gradle (#2319)
1 parent 0ee93ac commit c69bcc3

21 files changed

+569
-70
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ jobs:
1515
uses: actions/setup-java@v3
1616
with:
1717
distribution: 'temurin'
18-
java-version: '17'
19-
cache: 'maven'
18+
java-version: '19'
19+
cache: 'gradle'
2020

21-
- name: Run maven build lifecycle
22-
run: mvn --batch-mode clean test package
21+
- name: Run gradle build lifecycle
22+
run: ./gradlew build shadowJar --no-daemon
2323

2424
- name: Upload plugin file
2525
uses: actions/upload-artifact@v2
2626
with:
2727
name: ProtocolLib
28-
path: target/ProtocolLib.jar
28+
path: build/libs/ProtocolLib.jar

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ jobs:
2626
uses: actions/setup-java@v3
2727
with:
2828
distribution: 'temurin'
29-
java-version: '17'
30-
cache: 'maven'
29+
java-version: '19'
30+
cache: 'gradle'
3131

3232
- name: Initialize CodeQL
3333
uses: github/codeql-action/init@v2
3434
with:
3535
languages: 'java'
3636

37-
- name: Run maven build lifecycle
38-
run: mvn --batch-mode clean test package
37+
- name: Run gradle build lifecycle
38+
run: ./gradlew build -x test --no-daemon
3939

4040
- name: Perform CodeQL Analysis
4141
uses: github/codeql-action/analyze@v2

Readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ Currently maintained by dmulloy2 on behalf of [Spigot](https://www.spigotmc.org/
2020

2121
### Compilation
2222

23-
ProtocolLib is built with [Maven](https://maven.apache.org/). If you have it installed, just run
24-
`mvn package` in the root project folder.
23+
ProtocolLib is built with [Gradle](https://gradle.org/). If you have it installed, just run
24+
`./gradlew build` in the root project folder. Other gradle targets you may be interested in
25+
include `clean`, `test`, and `shadowJar`. `shadowJar` will create a jar with all dependencies
26+
(ByteBuddy) included.
2527

2628
### A new API
2729

@@ -53,7 +55,7 @@ You can also add ProtocolLib as a Maven dependency:
5355
<dependency>
5456
<groupId>com.comphenix.protocol</groupId>
5557
<artifactId>ProtocolLib</artifactId>
56-
<version>4.7.0</version>
58+
<version>5.0.0-SNAPSHOT</version>
5759
<scope>provided</scope>
5860
</dependency>
5961
</dependencies>
@@ -67,7 +69,7 @@ repositories {
6769
}
6870
6971
dependencies {
70-
compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "4.7.0";
72+
compileOnly 'com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT'
7173
}
7274
```
7375

build.gradle

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
plugins {
2+
id 'java-library'
3+
id 'maven-publish'
4+
id 'com.github.johnrengelman.shadow' version '8.1.1'
5+
}
6+
7+
group = 'com.comphenix.protocol'
8+
version = '5.0.0-SNAPSHOT'
9+
description = 'Provides access to the Minecraft protocol'
10+
11+
def isSnapshot = version.endsWith('-SNAPSHOT')
12+
13+
repositories {
14+
// mavenLocal() // can speed up build, but may fail in CI
15+
mavenCentral()
16+
17+
maven {
18+
url 'https://repo.dmulloy2.net/repository/public/'
19+
}
20+
21+
maven {
22+
url 'https://hub.spigotmc.org/nexus/content/groups/public/'
23+
}
24+
25+
maven {
26+
url 'https://libraries.minecraft.net/'
27+
metadataSources {
28+
mavenPom()
29+
artifact()
30+
ignoreGradleMetadataRedirection()
31+
}
32+
}
33+
}
34+
35+
dependencies {
36+
implementation 'net.bytebuddy:byte-buddy:1.14.3'
37+
compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT'
38+
compileOnly 'org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT'
39+
compileOnly 'io.netty:netty-all:4.0.23.Final'
40+
compileOnly 'net.kyori:adventure-text-serializer-gson:4.13.0'
41+
compileOnly 'com.googlecode.json-simple:json-simple:1.1.1'
42+
43+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
44+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
45+
testImplementation 'org.mockito:mockito-core:4.11.0'
46+
testImplementation 'org.mockito:mockito-inline:4.11.0'
47+
testImplementation 'io.netty:netty-common:4.1.77.Final'
48+
testImplementation 'io.netty:netty-transport:4.1.77.Final'
49+
testImplementation 'org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT'
50+
}
51+
52+
java {
53+
sourceCompatibility = JavaVersion.VERSION_1_8
54+
targetCompatibility = JavaVersion.VERSION_1_8
55+
56+
withJavadocJar()
57+
withSourcesJar()
58+
}
59+
60+
shadowJar {
61+
dependencies {
62+
include(dependency('net.bytebuddy:byte-buddy:.*'))
63+
}
64+
relocate 'net.bytebuddy', 'com.comphenix.net.bytebuddy'
65+
archiveFileName = 'ProtocolLib.jar'
66+
}
67+
68+
test {
69+
useJUnitPlatform()
70+
}
71+
72+
processResources {
73+
def includeBuild = isSnapshot && System.getenv('BUILD_NUMBER')
74+
def fullVersion = includeBuild
75+
? version + '-' + System.getenv('BUILD_NUMBER')
76+
: version
77+
78+
eachFile { expand(['version': fullVersion]) }
79+
}
80+
81+
publishing {
82+
publications {
83+
mavenJava(MavenPublication) {
84+
from components.java
85+
86+
afterEvaluate {
87+
artifactId = 'ProtocolLib'
88+
}
89+
}
90+
}
91+
92+
repositories {
93+
maven {
94+
url isSnapshot
95+
? 'https://repo.dmulloy2.net/repository/snapshots/'
96+
: 'https://repo.dmulloy2.net/repository/releases/'
97+
98+
credentials {
99+
username project.nexusUsername
100+
password project.nexusPassword
101+
}
102+
}
103+
}
104+
}
105+
106+
tasks.withType(JavaCompile) {
107+
options.encoding = 'UTF-8'
108+
}
109+
110+
tasks.withType(Javadoc) {
111+
options.encoding = 'UTF-8'
112+
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nexusUsername=""
2+
nexusPassword=""

gradle/wrapper/gradle-wrapper.jar

60.2 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
4+
networkTimeout=10000
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)