英文:
Set up picocli Annotation Processor in Intellij maven project with modules
问题
我无法理解如何在基于Maven的IntelliJ项目中设置picocli注解处理器。
考虑以下主POM:
<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>
<!-- 其他依赖 -->
</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>
</plugins>
</build>
</project>
picocli代码位于核心模块。但是,一旦我在编译器插件中添加配置,所有我的IntelliJ配置都变得无效。无论我是将pico配置放在主模块还是核心模块,两者都不起作用。核心模块的POM仅用于测试和打包。
代码仍然可以编译并且可用作jar(没有编译时错误检查),但在IntelliJ中无法使用。示例可以工作,但它不使用模块。
我应该怎么在IntelliJ中修复这个问题?
英文:
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>
</project>
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
得分: 1
这似乎是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配置。
例如,将以下内容放入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>
因此,问题与IntelliJ有关。感谢Remko Popma的帮助来解决这个问题。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论