Set up picocli Annotation Processor in Intellij maven project with modules

886 views Asked by At

I'm can't figure out how to setup picocli Anotation processor in a maven based intellij project.

Considere the following main pom:

<?xml version="1.0" encoding="UTF-8"?>

<groupId>my.group.id</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<modules>
        <module>core</module>
        <module>util</module>
</modules>

<dependencies>
    <dependency>
        <groupId>info.picocli</groupId>
        <artifactId>picocli</artifactId>
        <version>4.5.1</version>
    </dependency>
    <!-- Other dependencies -->
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
      <annotationProcessorPaths>
        <path>
          <groupId>info.picocli</groupId>
          <artifactId>picocli-codegen</artifactId>
          <version>4.5.1</version>
        </path>
      </annotationProcessorPaths>
      <compilerArgs>
        <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
      </compilerArgs>
    </configuration>
        </plugin>
</build>

The picocli code is in the core module. But as soon as I add the configuration in the complier plugin all my IntlliJ configuration become invalid. It doesn't matter if I put the pico config in the main module or the core, both don't work. The core module pom is just for testing and packaging.

The code still compiles and is usable as an jar (No compile time err checking), but not in IntelliJ. The example works. But it doesn't use modules.

What can I do to fix it in intelliJ?

1

There are 1 answers

0
AudioBubble On BEST ANSWER

This seams to be an issue with IntelliJ not properly handling non standard maven projects.

A maven project that follows standard java rules:

$PROJECT
│  pom.xml
│  ReadMe.md
├─core
│  │  pom.xml
│  └─src
│      └─main
│          └─java
│              └─your
│                  └─package
│                      └──Commons_cliTest.java
│                    
└─util
    │  pom.xml
    └─src
        └─main
            └─java
                └─your
                    └─package
                       └─YourClasses.java

This works perfectly fine. You just need set the picocli config in the child module pom.

For example, put this in the core pom.xml

    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <annotationProcessorPaths>
                <path>
                    <groupId>info.picocli</groupId>
                    <artifactId>picocli-codegen</artifactId>
                    <version>4.5.1</version>
               </path>
            </annotationProcessorPaths>
            <compilerArgs>
                <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
            </compilerArgs>
        </configuration>
    </plugin>

So the problem is IntelliJ related. Thanks for the help form Remko Popma to figure this out