Skip to content

Commit

Permalink
Switch from Meson to Maven
Browse files Browse the repository at this point in the history
Maven is commonly used for Java packages; Meson is not.  Also, Meson's
Java support is incomplete and we've had to carry workarounds for adding
entries to the JAR manifest.

Historically the built artifact has been called openslide.jar.  We're
already renaming it to openslide-java-$version.jar in CI, and Maven
prefers to include the version number in the JAR filename.  For clarity
and consistency, use Maven's defaults with a sensible artifactId, building
the artifact as openslide-java-$version.jar.

Allow Maven to add its usual additional metadata to the JAR, including a
couple MANIFEST.MF properties and a complete copy of pom.xml.

Document selecting the correct JDK version at build time, if needed.
Maven does not necessarily run on the latest, or default, JDK on the
system (e.g. Fedora pins it to an older LTS), so it may be necessary to
explicitly set JAVA_HOME.

We don't learn that our JDK is too old until we try to compile with it.
The Maven toolchains mechanism could prevent this, but toolchains are not
autodiscovered: they must be explicitly configured by the environment,
which often does not do this.  (In GitHub Actions, actions/setup-java does
set up a toolchains file, but Fedora and Ubuntu do not.)  If we declared a
toolchain dependency, we would require the user to set up a toolchains
file before building; it's easier to not do this, and fail at build time if
Java is too old.

Maven prints warnings unless pom.xml hardcodes version numbers for every
plugin mentioned there.  If version numbers are specified, Maven fetches
and runs exactly those plugin versions, with no way to smoothly use the
latest available version.  Maven calls these version pins a "good
practice", but really they're an antipattern that encourages continued
reliance on old versions of build tooling, making the ecosystem more
brittle.  Mitigate as best we can: hardcode plugin versions to avoid the
warning, then enable monthly Dependabot version updates so we don't retain
pins to stale versions.

Closes: #68
Signed-off-by: Benjamin Gilbert <[email protected]>
  • Loading branch information
bgilbert committed Apr 10, 2024
1 parent 294ec9a commit 3cbcc86
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/release.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenSlide Java release process

- [ ] Update `CHANGELOG.md` and version in `meson.build`
- [ ] Update `CHANGELOG.md` and version in `pom.xml`
- [ ] Create and push signed tag
- [ ] Verify that GitHub Actions created a [GitHub release](https://github.com/openslide/openslide-java/releases) with release notes and a JAR
- [ ] Update website: `_data/releases.yaml`, `_includes/news.md`
Expand Down
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
# Periodically check for Maven plugin updates
- package-ecosystem: maven
directory: /
schedule:
interval: monthly
commit-message:
prefix: maven
22 changes: 8 additions & 14 deletions .github/workflows/java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,22 @@ jobs:
with:
distribution: oracle
java-version: 22
cache: maven
- name: Install dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install libopenslide0 ninja-build
# Ubuntu 22.04 packages Meson 0.61
pip install --user meson
sudo apt-get install libopenslide0
- name: Install dependencies (macOS)
if: matrix.os == 'macos-14'
run: |
brew install meson openslide
brew install openslide
# allow smoke test to find OpenSlide
echo "DYLD_LIBRARY_PATH=/opt/homebrew/lib" >> $GITHUB_ENV
- name: Install dependencies (Windows)
if: matrix.os == 'windows-latest'
env:
GH_TOKEN: ${{ github.token }}
run: |
pip install meson ninja
mkdir -p "c:\\openslide"
cd "c:\\openslide"
release=$(gh release list -R openslide/openslide-bin -L 1 \
Expand All @@ -64,24 +62,20 @@ jobs:
# allow smoke test to find OpenSlide
echo "PATH=c:\\openslide\\${zipname}\\bin;$PATH" >> $GITHUB_ENV
- name: Build
run: |
meson setup builddir
meson compile -C builddir
run: mvn -Dmaven.compiler.failOnWarning=true
- name: Smoke test
run: |
java --enable-native-access=ALL-UNNAMED -cp builddir/openslide.jar \
org.openslide.TestCLI fixtures/small.svs
java --enable-native-access=ALL-UNNAMED \
-cp target/openslide-java-*.jar org.openslide.TestCLI \
fixtures/small.svs
- name: Dist
id: dist
if: matrix.dist
run: |
set -o pipefail
dist="openslide-java-dist-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)"
echo "dist-base=$dist" >> $GITHUB_OUTPUT
mkdir -p "artifacts/$dist"
version=$(meson introspect --projectinfo builddir | jq -r .version)
mv builddir/openslide.jar \
"artifacts/${dist}/openslide-java-${version}.jar"
mv target/openslide-java-*.jar "artifacts/${dist}"
- name: Archive dist
if: matrix.dist
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a Java binding to [OpenSlide](https://openslide.org/).
## Build requirements

- JDK ≥ 22
- Meson &ge; 0.62
- Maven


## Runtime requirements
Expand All @@ -19,11 +19,17 @@ This is a Java binding to [OpenSlide](https://openslide.org/).
## Building

```
meson setup builddir
meson compile -C builddir
mvn
```

The JAR will be in `builddir/openslide.jar`.
The JAR will be in `target/openslide-java-*.jar`.

If you have multiple JVMs on your system, and Maven defaults to a version
older than 22, you might need to set `JAVA_HOME`. For exmaple, on Fedora:

```
JAVA_HOME=/usr/lib/jvm/java-22 mvn
```


## License
Expand Down
69 changes: 0 additions & 69 deletions meson.build

This file was deleted.

5 changes: 0 additions & 5 deletions meta/MANIFEST.MF.in

This file was deleted.

108 changes: 108 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<version>0.12.4</version>

<groupId>org.openslide</groupId>
<artifactId>openslide-java</artifactId>
<name>OpenSlide Java</name>
<description>Java interface to OpenSlide</description>
<url>https://openslide.org</url>
<inceptionYear>2007</inceptionYear>
<organization>
<name>OpenSlide project</name>
<url>https://openslide.org</url>
</organization>
<licenses>
<license>
<name>LGPL-2.1-only</name>
<url>https://raw.githubusercontent.com/openslide/openslide-java/main/COPYING.LESSER</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>

<build>
<defaultGoal>package</defaultGoal>
<sourceDirectory>.</sourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all,-serial</arg>
</compilerArgs>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>org.openslide.gui.Demo</mainClass>
</manifest>
<manifestEntries>
<Enable-Native-Access>ALL-UNNAMED</Enable-Native-Access>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<distributionManagement>
<downloadUrl>https://openslide.org/download/#source</downloadUrl>
</distributionManagement>

<scm>
<connection>scm:git:https://github.com/openslide/openslide-java</connection>
<url>https://github.com/openslide/openslide-java</url>
</scm>

<issueManagement>
<system>GitHub</system>
<url>https://github.com/openslide/openslide-java/issues</url>
</issueManagement>

<ciManagement>
<system>GitHub</system>
<url>https://github.com/openslide/openslide-java/actions</url>
</ciManagement>

<mailingLists>
<mailingList>
<name>openslide-announce</name>
<subscribe>https://lists.andrew.cmu.edu/mailman/listinfo/openslide-announce</subscribe>
<unsubscribe>https://lists.andrew.cmu.edu/mailman/listinfo/openslide-announce</unsubscribe>
<archive>https://lists.andrew.cmu.edu/pipermail/openslide-announce/</archive>
<otherArchives>
<otherArchive>https://marc.info/?l=openslide-announce</otherArchive>
</otherArchives>
</mailingList>
<mailingList>
<name>openslide-users</name>
<subscribe>https://lists.andrew.cmu.edu/mailman/listinfo/openslide-users</subscribe>
<unsubscribe>https://lists.andrew.cmu.edu/mailman/listinfo/openslide-users</unsubscribe>
<post>[email protected]</post>
<archive>https://lists.andrew.cmu.edu/pipermail/openslide-users/</archive>
<otherArchives>
<otherArchive>https://marc.info/?l=openslide-users</otherArchive>
</otherArchives>
</mailingList>
</mailingLists>
</project>

0 comments on commit 3cbcc86

Please sign in to comment.