org.openrewrite.java.migrate.maven.UseMavenCompilerPluginReleaseConfiguration
Replaces any explicit source
or target
configuration (if present) on the maven-compiler-plugin with release
, and updates the release
value if needed. Will not downgrade the java version if the current version is higher.
GitHub, Issue Tracker, Maven Central
- groupId: org.openrewrite.recipe
- artifactId: rewrite-migrate-java
- version: 2.0.1
Type | Name | Description |
---|---|---|
String |
releaseVersion | The new value for the release configuration. This recipe prefers ${java.version} if defined. |
Parameter | Value |
---|---|
releaseVersion | 11 |
{% tabs %} {% tab title="pom.xml" %}
{% code title="pom.xml" %}
<?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>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
{% endcode %}
{% code title="pom.xml" %}
<?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>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
{% endcode %}
{% endtab %} {% tab title="Diff" %} {% code %}
--- pom.xml
+++ pom.xml
@@ -15,2 +15,1 @@
<version>3.8.0</version>
<configuration>
- <source>1.8</source>
- <target>1.8</target>
+ <release>11</release>
</configuration>
{% endcode %} {% endtab %} {% endtabs %}
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly. To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml
create a new recipe with a unique name. For example: com.yourorg.UseMavenCompilerPluginReleaseConfigurationExample
.
Here's how you can define and customize such a recipe within your rewrite.yml:
{% code title="rewrite.yml" %}
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.UseMavenCompilerPluginReleaseConfigurationExample
displayName: Use Maven Compiler Plugin Release Configuration example
recipeList:
- org.openrewrite.java.migrate.maven.UseMavenCompilerPluginReleaseConfiguration:
releaseVersion: 11
{% endcode %}
Now that com.yourorg.UseMavenCompilerPluginReleaseConfigurationExample
has been defined activate it and take a dependency on org.openrewrite.recipe:rewrite-migrate-java:2.0.1 in your build file:
{% tabs %}
{% tab title="Maven" %} {% code title="pom.xml" %}
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<activeRecipes>
<recipe>com.yourorg.UseMavenCompilerPluginReleaseConfigurationExample</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
{% endcode %} {% endtab %} {% endtabs %}
The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.