Integrating private code with Moderne SaaS
Having your build publish AST files to an artifact repository under your control is part of setting up the Moderne SaaS in your company's environment. This guide will show you how to set up your Maven and Gradle builds accordingly.
Connecting your private code to the Moderne SaaS is the only reason to use these plugins instead of the OpenRewrite plugins. If you are not connecting private code to the Moderne SaaS you should use the OpenRewrite plugins instead.

Step 1: Apply moderne-maven-plugin or moderne-gradle-plugin

In the pom.xml or build.gradle, add this entry to the plugins section to apply the moderne plugin to the project.
Maven
Gradle
pom.xml
1
<project>
2
<build>
3
<plugins>
4
<plugin>
5
<groupId>io.moderne</groupId>
6
<artifactId>moderne-maven-plugin</artifactId>
7
<version>0.10.0</version>
8
<configuration>
9
<!-- Supports all of the same functionality as the OpenRewrite plugin -->
10
<activeRecipes>
11
<recipe>org.openrewrite.java.cleanup.CommonStaticAnalysis</recipe>
12
</activeRecipes>
13
</configuration>
14
<executions>
15
<execution>
16
<phase>package</phase>
17
<goals><goal>ast</goal></goals>
18
</execution>
19
</executions>
20
</plugin>
21
</plugins>
22
</build>
23
</project>
Copied!
build.gradle
1
plugins {
2
id("io.moderne.rewrite") version("0.13.0")
3
}
4
​
5
// OpenRewrite and recipe modules are published to Maven Central
6
// This repository, or a mirror, must be available
7
repositories {
8
mavenCentral()
9
}
10
​
11
rewrite {
12
// Supports all of the same functionality as the OpenRewrite plugin
13
}
Copied!
The Moderne build plugins offer all the functionality and configuration options of their OpenRewrite counterparts. If you were previously applying the OpenRewrite plugins, you can remove those declarations from your build files.
If you're a Maven user used to command line invocations such as mvn rewrite:dryRun or mvn rewrite:run, note that these invocations become mvn moderne:dryRun and mvn moderne:run. If you wish to continue invoking these commands with the "rewrite" prefix, such as to avoid having to alter CI workflows invoking mvn rewrite:dryRun, you can apply both plugins without conflict.
Gradle users can continue invoking gradlew rewriteDryRun and gradlew rewriteRun as the names of those tasks remain the same in the moderne-gradle-plugin.

Step 2: Configure Publishing

The Moderne SaaS requires that the AST artifacts produced by the build plugin be published to your artifact repository. This may require you to publish AST artifacts from projects that do not currently publish anything.
Maven
Gradle
Typically, no additional publishing configuration is required for Maven builds.
Each project the plugin is applied to will have a Jar task named moderneJar which produces the AST jar in the project's build folder. This is the file that needs to be published to your artifact repository to enable Moderne SaaS integration.
single project build
1
plugins {
2
id("io.moderne.rewrite") version("0.8.1")
3
id("maven-publish")
4
}
5
​
6
publishing {
7
repositories {
8
// your repository configuration
9
}
10
publishing {
11
publications {
12
create("moderne", MavenPublication.class) {
13
artifact(tasks.named("moderneJar"))
14
}
15
}
16
}
17
}
Copied!

Step 3: Build and publish the next version of your project

Now whenever your project is published there will be a file with a "jar" extension and an "ast" classifier published alongside any other publications. So for a project named "example" publishing version "1.0", you can expect to see a file named example-1.0-ast.jar alongside the normal example-1.0.jar.

See Also