Skip to content

Commit

Permalink
Merge pull request #47 from avaje/JDK-24
Browse files Browse the repository at this point in the history
JDK 24
  • Loading branch information
SentryMan authored Dec 17, 2024
2 parents ba1e3fb + f101391 commit 4913661
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: [23]
java_version: [24]
os: [ubuntu-latest]

steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/jdk-ea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: JDK EA

on:
push:
workflow_dispatch:
schedule:
- cron: '39 6 * * 1,3,5'
Expand All @@ -16,7 +17,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
15 changes: 5 additions & 10 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 Down
16 changes: 2 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<groupId>io.avaje</groupId>
<artifactId>avaje-provides-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.2-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>23</maven.compiler.release>
<maven.compiler.release>24</maven.compiler.release>
</properties>

<dependencies>
Expand Down Expand Up @@ -48,22 +48,10 @@
<goalPrefix>avaje-provides</goalPrefix>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
--enable-preview
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
<configuration>
<additionalOptions>--enable-preview</additionalOptions>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ public class DisableModuleValidationMojo 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) {
getLog()
.warn(
"This version of the avaje-provides-plugin only works on JDK 23 with --enable-preview cofigured in MAVEN_OPTS");
if (Integer.getInteger("java.specification.version") < 24) {
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 4913661

Please sign in to comment.