A build pipeline setup [Maven + GitHub]

Posted by Jannyboy11 in Plugin Development · · 0 replies · 2 views

Jannyboy11 ·

Hey community. Today I've been working on automating the release process to MC-Foundry for two of my plugins. In this post I'd like to describe the setup; the goal is to share knowledge, and to gather feedback. I'm a bit oldschool in the sense that I still use Maven over Gradle, and Spigot over Paper, but that shouldn't influence the process too much - the main ideas still hold. The process described is taken from a real-world open-source plugin, which can be inspected as an example. Step 1. Decide your desired builld setup. I decided on the following requirements for this setup: I want publishing to work from the commandline on my local machine - no manual uploading jars via a browser window. The plugin has an API, and should be published to a maven repository, for consumption by others. Javadocs should also be published somewhere. Since the source code lives on GitHub, I also want to make use of GitHub releases. An nice bonus is that this enables the built-in version upload integration from MC-Foundry. Step 2. Figure out the proper process to make releases using your build tool. For Maven, a good default option is to use the Maven Release Plugin. This will add a few goals to the Maven build, most importantly mvn release:prepare and mvn release:perform. When these commands are executed, a few things happen: The maven-release-plugin will bump the version of the project, and create some backup files (that could be used by mvn release:rollback). A git tag will also be created locally. The project will be built, and the artifacts are uploaded to some maven repository. The maven repositories for uploading can be configured in the section of the pom.xml project file. Since I don't self-host a maven repository, I am choosing two free options: GitHub Packages and Repsy. GitHub will be used for release versions of the software, while Repsy will be used for snapshot versions only - since GitHub Packages repositories are a bit limited in size. Other notable options are JitPack and Maven Central, but I didn't want to deal with their restrictions for this project. The configuration in the pom.xml looks as follows: In addition to this, there is also a bit of configuration necessary in the local .m2/settings.xml file. More on that explained here. A bit more configuration is necessary for the remote git repository, and for the commits created by the Maven Release Plugin: Note: if you were using Gradle, then you'd use the maven-publish Gradle plugin. Step 3. Implement the CI workflow. The easiest way is to use the provided CI environment of the git hosting solution, if available. For GitHub, that is GitHub Actions. At its core it is just a task engine that can run commands inside Docker containers. We will use this for javadoc deployment, and for creating the releases on GitHub automatically. My workflow file looks as follows: As can be seen, this build has two jobs: build: compiles all sources, runs all tests, and creates the jar artifact. This job runs for every push to GitHub. release: publishes the artifact to GitHub Releases, and publishes the Javadoc. This job only runs when a git tag was pushed to GitHub (note: this happens through mvn release:perform). To get this workflow to pass, a bit of extra setup is required, I won't go in detail here, but here are some links: setup-java action: https://github.com/actions/setup-java upload-artifact action: https://github.com/actions/upload-artifact download-artifact action: https://github.com/actions/download-artifact Javadoc-publisher action: https://github.com/MathieuSoysal/Javadoc-publisher.yml gh-release action: https://github.com/softprops/action-gh-release Step 4. Enable GitHub Releases integration in MC-Foundry, follow the 'The Easy Way' guide here. Step 5. Profit!! We now have a build and release setup that works as follows: Developer executes mvn release:prepare and mvn release:perform locally. Maven builds the release version of the software, and publishes it to the configured maven repository for release versions. Maven also pushes a tag to the repository on GitHub, kicking of the release process in GitHub actions. The GitHub actions workflow compiles the sources again, and uploads the jar artifact to GitHub Releases, and the Javadocs are published to GitHub Pages. MC-Foundry's sync kicks in, and the new version is also created on the MC-Foundry project page. Deployment of a snapshot version is possible with the mvn deploy command. That's all I have. Let me know your thoughts; questions, comments and suggestions welcome!

Join the discussion

Reply on MC-Foundry. A free account lets you reply, get notified of answers and bookmark threads.