问题描述
我不知道如何在基于Maven的intellij项目中设置picocli注释处理器。
请考虑以下主要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>
picocli代码在核心模块中。但是,一旦我在complier插件中添加了配置,我所有的IntlliJ配置都将失效。我将pico config放在主模块或核心中都没关系,两者都不起作用。核心模块pom仅用于测试和包装。
该代码仍然可以编译,并且可以作为jar使用(无需检查编译时间err),但是不能在IntelliJ中使用。 example有效。但是它不使用模块。
我该如何解决intelliJ的问题?
解决方法
这似乎是IntelliJ无法正确处理非标准Maven项目的问题。
遵循标准Java规则的Maven项目:
$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
这很好用。您只需要在子模块pom中设置picocli配置。
例如,将其放入核心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>
因此,问题与IntelliJ有关。 感谢Remko Popma的帮助表格以解决此问题