Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to gradle, java 17 and fix examples #769

Merged
merged 29 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0f28b75
Migrate to gradle, java 17 and fix examples
AlexProgrammerDE Dec 11, 2023
6add53b
Attempt to fix compilation
AlexProgrammerDE Dec 11, 2023
9af2d8b
Update gradle wrapper
AlexProgrammerDE Dec 11, 2023
3b9f1a4
Point to javadocs
AlexProgrammerDE Dec 11, 2023
8afa903
Initial work on gradle deploy
AlexProgrammerDE Dec 12, 2023
144e231
Downgrade to java 16 and adapt gradle workflows
AlexProgrammerDE Dec 12, 2023
384e528
Validate wrapper on deploy as well
AlexProgrammerDE Dec 12, 2023
3606954
Migrate to version catalog
AlexProgrammerDE Dec 12, 2023
a83dc19
Revert "Downgrade to java 16 and adapt gradle workflows"
AlexProgrammerDE Dec 13, 2023
b7be0ed
Fix workflows
AlexProgrammerDE Dec 13, 2023
8e63bd6
Remove unnecessary flag
AlexProgrammerDE Dec 13, 2023
ba516be
Update netty and improve lombok plugin
AlexProgrammerDE Dec 13, 2023
e245dd5
Update to 102
AlexProgrammerDE Dec 13, 2023
ff04406
Bump to 103
AlexProgrammerDE Dec 13, 2023
8266465
Merge remote-tracking branch 'upstream/master' into gradle-java
AlexProgrammerDE Dec 15, 2023
8dcc7b5
Some work on requested changes
AlexProgrammerDE Dec 15, 2023
7e45089
Reconfigure javadocs
AlexProgrammerDE Dec 15, 2023
a294952
Stop using deprecated module
AlexProgrammerDE Dec 15, 2023
cb9703c
Change imports to wanted style
AlexProgrammerDE Dec 16, 2023
4499e93
Merge remote-tracking branch 'upstream/master' into gradle-java
AlexProgrammerDE Dec 16, 2023
dc7ddf9
Add back comment
AlexProgrammerDE Dec 16, 2023
4e3393e
Use weird version catalog layout
AlexProgrammerDE Dec 17, 2023
48df6f6
Revert packet changes
AlexProgrammerDE Dec 17, 2023
8562e64
Revert all style changes
AlexProgrammerDE Dec 17, 2023
6404430
Delete unused classes
AlexProgrammerDE Dec 17, 2023
d31ca4f
Revert "Delete unused classes"
AlexProgrammerDE Dec 17, 2023
70c9917
Fix import
AlexProgrammerDE Dec 17, 2023
f55d178
Merge remote-tracking branch 'upstream/master' into gradle-java
AlexProgrammerDE Dec 19, 2023
0c31e09
Address review
AlexProgrammerDE Dec 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Java CI with Gradle

on: [push, pull_request]

jobs:
build:
# Only run on PRs if the source branch is on someone else's repo
if: "${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}"

runs-on: ubuntu-latest

steps:
- name: Checkout repository
# See https://github.com/actions/checkout/commits
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

- name: Validate Gradle wrapper
# See https://github.com/gradle/wrapper-validation-action/commits
uses: gradle/wrapper-validation-action@342dbebe7272035434f9baccc29a816ec6dd2c7b

- name: Set up JDK 17
# See https://github.com/actions/setup-java/commits
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0
with:
java-version: 17
distribution: temurin

- name: Build
# See https://github.com/gradle/gradle-build-action/commits
uses: gradle/gradle-build-action@3bfe3a46584a206fb8361cdedd0647b0c4204232
with:
arguments: build
20 changes: 11 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ jobs:
# See https://github.com/actions/checkout/commits
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

- name: Validate Gradle wrapper
# See https://github.com/gradle/wrapper-validation-action/commits
uses: gradle/wrapper-validation-action@342dbebe7272035434f9baccc29a816ec6dd2c7b

- name: Set up JDK 17
# See https://github.com/actions/setup-java/commits
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0
with:
java-version: 17
distribution: temurin

- uses: s4u/maven-settings-action@60912582505985be4cc55d2b890eb32767f8de5f
# See https://github.com/s4u/maven-settings-action/commits
with:
servers: '[{"id": "opencollab-release-repo", "username": "${env.MAVEN_USERNAME}", "password": "${env.MAVEN_PASSWORD}"},{"id": "opencollab-snapshot-repo", "username": "${env.MAVEN_USERNAME}", "password": "${env.MAVEN_PASSWORD}"}]'

- name: Deploy with Maven
run: mvn deploy -B -P deploy
- name: Publish to Maven Repository
if: ${{ success() && github.repository == 'GeyserMC/MCProtocolLib' && github.ref_name == 'master' }}
uses: gradle/gradle-build-action@3bfe3a46584a206fb8361cdedd0647b0c4204232
env:
MAVEN_USERNAME: ${{ vars.DEPLOY_USER }}
MAVEN_PASSWORD: ${{ secrets.DEPLOY_PASS }}
OPENCOLLAB_USERNAME: ${{ vars.DEPLOY_USER }}
OPENCOLLAB_PASSWORD: ${{ secrets.DEPLOY_PASS }}
with:
arguments: publish
23 changes: 0 additions & 23 deletions .github/workflows/maven.yml

This file was deleted.

34 changes: 26 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
bin
lib
target
testing
# Compiled plugin files
target/

.settings
# IDE files
.idea/
.vscode/*
.settings/*
*.iml
*.iws
*.ipr
.classpath
.project
.directory
.factorypath

*.iml
.idea
# UML
*.plantuml

# Gradle
.gradle
**/build/
!src/**/build/
**/run/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache
7 changes: 3 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pipeline {
agent any
tools {
maven 'Maven 3'
jdk 'Java 17'
}
options {
Expand All @@ -10,7 +9,7 @@ pipeline {
stages {
stage ('Build') {
steps {
sh 'mvn clean package'
sh './gradlew clean build'
}
}

Expand All @@ -20,8 +19,8 @@ pipeline {
}

steps {
sh 'mvn javadoc:javadoc'
step([$class: 'JavadocArchiver', javadocDir: 'target/site/apidocs', keepAll: false])
sh './gradlew javadoc'
step([$class: 'JavadocArchiver', javadocDir: 'build/docs/javadoc', keepAll: false])
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ dependencies {

To use snapshot builds, switch the URL to `https://repo.opencollab.dev/maven-snapshots/`.

### Javadocs

You can find the Javadocs for MCProtocolLib [on opencollab](https://ci.opencollab.dev/job/GeyserMC/job/MCProtocolLib/job/master/javadoc/overview-summary.html).

## Building the Source

MCProtocolLib uses Maven to manage dependencies. To build the source code, run `mvn clean install` in the project root directory.
Expand Down
112 changes: 112 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
plugins {
idea
`java-library`
`maven-publish`
alias(libs.plugins.indra)
alias(libs.plugins.indra.git)
alias(libs.plugins.indra.publishing)
alias(libs.plugins.lombok)
}

indra {
github("GeyserMC", "MCProtocolLib")

mitLicense()
publishReleasesTo("opencollab-release-repo", "https://repo.opencollab.dev/maven-releases/")
publishSnapshotsTo("opencollab-snapshot-repo", "https://repo.opencollab.dev/maven-snapshots/")

configurePublications {
pom {
name = "MCProtocolLib"
url = "https://github.com/GeyserMC/MCProtocolLib/"
organization {
name = "GeyserMC"
url = "https://github.com/GeyserMC"
}
developers {
developer {
id = "steveice10"
name = "Steveice10"
email = "Steveice10@gmail.com"
}
developer {
id = "GeyserMC"
name = "GeyserMC"
url = "https://geysermc.org/"
}
}
}

versionMapping {
usage(Usage.JAVA_API) { fromResolutionOf(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) }
usage(Usage.JAVA_RUNTIME) { fromResolutionResult() }
}
}

javaVersions {
target(17)
strictVersions()
testWith(17)
minimumToolchain(17)
}
}

val repoName = if (version.toString().endsWith("SNAPSHOT")) "maven-snapshots" else "maven-releases"
publishing {
repositories {
maven("https://repo.opencollab.dev/${repoName}/") {
credentials.username = System.getenv("OPENCOLLAB_USERNAME")
credentials.password = System.getenv("OPENCOLLAB_PASSWORD")
name = "opencollab"
}
}
}

dependencies {
// Minecraft related libraries
AlexProgrammerDE marked this conversation as resolved.
Show resolved Hide resolved
api(libs.opennbt)
api(libs.mcauthlib)

// Kyori adventure
api(libs.bundles.adventure)

// Math utilities
api(libs.bundles.math)

// Stripped down fastutil
api(libs.bundles.fastutil)

// Netty
api(libs.bundles.netty)

// Test dependencies
testImplementation(libs.junit.jupiter)
}

lombok {
version = libs.versions.lombok.version.get()
}

group = "com.github.steveice10"
version = "1.20.4-2-SNAPSHOT"
description = "MCProtocolLib is a simple library for communicating with Minecraft clients and servers."

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:all,-processing")
}

tasks.withType<Javadoc> {
title = "MCProtocolLib Javadocs"
val options = options as StandardJavadocDocletOptions
options.encoding = "UTF-8"
options.addStringOption("Xdoclint:all,-missing", "-quiet")
}

11 changes: 11 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
java
}

dependencies {
implementation(rootProject)
}

tasks.javadoc {
onlyIf { false }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import com.github.steveice10.opennbt.NBTIO;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.packetlib.ProxyInfo;
import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
Expand All @@ -39,16 +37,11 @@
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.zip.GZIPInputStream;

public class MinecraftProtocolTest {
private static final boolean SPAWN_SERVER = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.packet.Packet;

import java.io.IOException;
import io.netty.buffer.ByteBuf;

public class PingPacket implements Packet {
private final String id;

public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) {
this.id = codecHelper.readString(buf);
}

Expand All @@ -19,14 +18,4 @@ public PingPacket(String id) {
public String getPingId() {
return this.id;
}

@Override
public void write(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
codecHelper.writeString(buf, this.id);
}

@Override
public boolean isPriority() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import javax.crypto.SecretKey;

public class ServerListener extends ServerAdapter {
private SecretKey key;
private final SecretKey key;

public ServerListener(SecretKey key) {
this.key = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.codec.BasePacketCodecHelper;
import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.codec.PacketDefinition;
import com.github.steveice10.packetlib.codec.PacketSerializer;
import com.github.steveice10.packetlib.crypt.AESEncryption;
import com.github.steveice10.packetlib.crypt.PacketEncryption;
import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
import com.github.steveice10.packetlib.packet.PacketHeader;
import com.github.steveice10.packetlib.packet.PacketProtocol;
import io.netty.buffer.ByteBuf;

import javax.crypto.SecretKey;
import java.security.GeneralSecurityException;
Expand All @@ -28,10 +33,21 @@ public PacketCodecHelper createHelper() {
}

public void setSecretKey(SecretKey key) {
this.register(0, PingPacket.class, PingPacket::new);
this.register(0, PingPacket.class, new PacketSerializer<>() {
@Override
public void serialize(ByteBuf buf, PacketCodecHelper helper, PingPacket packet) {
helper.writeString(buf, packet.getPingId());
}

@Override
public PingPacket deserialize(ByteBuf buf, PacketCodecHelper helper, PacketDefinition<PingPacket, PacketCodecHelper> definition) {
return new PingPacket(buf, helper);
}
});

try {
this.encrypt = new AESEncryption(key);
} catch(GeneralSecurityException e) {
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
}
Expand Down
Loading