Skip to content

Commit

Permalink
use JDK 24
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Dec 16, 2024
1 parent 40c5b55 commit 2a027b6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/jdk-ea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: [GA,EA] ## valhalla,metropolis don't support java 17
java_version: [GA,EA]
os: [ubuntu-latest]

steps:
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Supported JVM Versions](https://img.shields.io/badge/JVM-23-brightgreen.svg?&logo=openjdk)
![Supported JVM Versions](https://img.shields.io/badge/JVM-24-brightgreen.svg?&logo=openjdk)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/avaje/avaje-inject/blob/master/LICENSE)
![Maven Central : avaje-provides-maven-plugin](https://img.shields.io/maven-central/v/io.avaje/avaje-provides-maven-plugin.svg?label=Maven%20Central)

Expand All @@ -8,10 +8,7 @@ Maven plugin that post-processes modular applications' `module-info.class` files

## How to use

### 1. Create a `.mvn/jvm.config` file
This plugin uses the JDK 22 [Class-File API](https://openjdk.org/jeps/457). As the feature is still in preview, create a `.mvn/jvm.config` file and add `--enable-preview` so that the maven JVM will run with preview features.

### 2. Add the plugin to your pom.xml
### 1. Add the plugin to your pom.xml

```xml
<plugin>
Expand All @@ -31,25 +28,23 @@ Given a module-info like:
```java
module avaje.example {
requires io.avaje.inject;
requires io.avaje.jsonb;

requires static io.avaje.spi;

}
```

And a `META-INF/my.example.SPIServiceInterface` file (either manually created or generated by APT):
And a `META-INF/services/my.example.SPIServiceInterface` file (either manually created or generated by APT):

```
my.example.SPIServiceInterfaceImpl
```
This goal will transform the module-info classfile after compilation to look like:

This goal will transform the module-info classfile after compilation to roughly look like:

```java
module avaje.example {
requires io.avaje.inject;
requires io.avaje.jsonb;
requires io.avaje.jsonb.plugin;

requires static io.avaje.spi;
provides my.example.SPIServiceInterface with my.example.SPIServiceInterfaceImpl;
Expand All @@ -58,4 +53,4 @@ module avaje.example {

### `disable-apt-validation`

As the `add-module-spi` goal runs after compilation, this goal generates a file before compilation that signals any apt project that uses avaje-prisms's `ModuleInfoReader` for service validation to disable `provides` module validation.
As the `add-module-spi` goal runs after compilation, this goal generates a file before compilation that signals any apt project that uses avaje-prisms's `ModuleInfoReader` for service validation to disable `provides` module validation.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<packaging>maven-plugin</packaging>
<version>1.2-SNAPSHOT</version>
<properties>
<maven.compiler.release>23</maven.compiler.release>
<maven.compiler.release>24</maven.compiler.release>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DisableModuleValidationMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {

if (Integer.getInteger("java.specification.version") < 24) {
getLog().warn("This version of the avaje-provides-plugin only works on JDK 24 and up");
getLog().error("This version of the avaje-provides-plugin only works on JDK 24 and up");
return;
}

Expand Down
12 changes: 3 additions & 9 deletions src/main/java/io/avaje/inject/mojo/ModuleSPIMojo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.avaje.inject.mojo;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -24,15 +22,11 @@ public class ModuleSPIMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {

var canRun =
Integer.getInteger("java.specification.version") == 23
&& ManagementFactory.getRuntimeMXBean().getInputArguments().stream()
.anyMatch("--enable-preview"::equals);

if (!canRun) {
if (Integer.getInteger("java.specification.version") < 24) {
getLog()
.warn(
"This version of the avaje-provides-plugin only works on JDK 23 with --enable-preview cofigured in MAVEN_OPTS");
.error(
"This version of the avaje-provides-plugin only works on JDK 24 and up");
return;
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/META-INF/plexus/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>avaje-inject-maven-plugin</role-hint>
<role-hint>avaje-provides-maven-plugin</role-hint>
<configuration>
<id>avaje-provides-maven-plugin</id>
<phases>
Expand All @@ -14,9 +14,6 @@
<process-resources>
io.avaje:avaje-provides-maven-plugin:${project.version}:disable-apt-validation
</process-resources>
<process-sources>
io.avaje:avaje-inject-maven-plugin:10.4:provides
</process-sources>
<process-classes>
io.avaje:avaje-provides-maven-plugin:${project.version}:add-module-spi
</process-classes>
Expand Down

0 comments on commit 2a027b6

Please sign in to comment.