I'm trying to build a modular application, and I'm attempting to use the moditect-maven-plugin in order to use the auto-value library (which is not modular).
Based on the instructions here, I came up with the following 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.example</groupId>
<artifactId>moditect-test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>${auto-value.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${auto-value.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.Beta2</version>
<executions>
<execution>
<id>generate-module-info</id>
<phase>generate-sources</phase>
<goals>
<goal>generate-module-info</goal>
</goals>
<configuration>
<modules>
<module>
<artifact>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>${auto-value.version}</version>
</artifact>
<moduleInfo>
<name>com.google.auto.value.annotations</name>
<exports>
com.google.auto.value;
*;
</exports>
</moduleInfo>
</module>
</modules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<auto-value.version>1.7</auto-value.version>
</properties>
The important portion is the moditect-maven-plugin configuration. Since I need the com.google.auto.value.AutoValue
annotation, I export that package and then give a relevant name to the module.
Just for reference, here's the class I'm using the annotation in:
package com.example.moditect.test;
import com.google.auto.value.AutoValue;
@AutoValue
abstract class Animal {
abstract String name();
abstract int numberOfLegs();
static Builder builder() {
return new AutoValue_Animal.Builder();
}
@AutoValue.Builder
abstract static class Builder {
abstract Builder setName(String value);
abstract Builder setNumberOfLegs(int value);
abstract Animal build();
}
}
...and here's the module-info.java
file of my application:
module com.example.moditect.test {
requires com.google.auto.value.annotations;
}
However, when I run mvn clean install
, I get the module not found
error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project moditect-test: Compilation failure
[ERROR] /home/someuser/development/workspace/moditect-test/src/main/java/module-info.java:[2,35] module not found: com.google.auto.value.annotations
It does appear that the moditect-maven-plugin is working based on these logs that get outputted when I run mvn clean install
:
[INFO] --- moditect-maven-plugin:1.0.0.Beta2:generate-module-info (generate-module-info) @ moditect-test ---
writing to /home/someuser/development/workspace/moditect-test/target/moditect/auto.value.annotations/module-info.java
[INFO] Created module descriptor at /home/someuser/development/workspace/moditect-test/target/generated-sources/modules/com.google.auto.value.annotations/module-info.java
And for what it's worth, here's the generated module-info of this auto-value library (from the location that's logged above):
module com.google.auto.value.annotations {
exports com.google.auto.value;
exports com.google.auto.value.extension.memoized;
}
So I need some help figuring out what I did wrong. I'm assuming I just messed up the configuration of the moditect-maven-plugin, but I'm not sure how.
I made the silly mistake of using the goal generate-module-info
instead of add-module-info
. Just switching the goal with the correct one solved this issue.