找不到Maven注释处理处理器 [英] Maven annotation processing processor not found

查看:34
本文介绍了找不到Maven注释处理处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是注释处理的新手,我正在尝试使用 Maven 对其进行自动化.我把它放在我的 pom.xml 中:

<插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.0</version><配置><annotationProcessors><annotationProcessor>co.aurasphere.revolver.annotation.processor.InjectAnnotationProcessor</annotationProcessor><annotationProcessor>co.aurasphere.revolver.annotation.processor.RevolverContextAnnotationProcessor</annotationProcessor></annotationProcessors><source>1.7</source><目标>1.7</目标></配置></插件></plugins>

问题是,当我尝试构建项目时,我收到 CompilationFailureException,因为 Maven 找不到处理器.

我发现了其他类似的问题,通过将依赖项放在插件之外来解决.我试过了,但对我来说没有任何改变.

我错过了什么吗?

谢谢.

编辑

这是我对另一个包含处理器和注释的项目的依赖:

 <依赖><groupId>co.aurasphere</groupId><artifactId>左轮手枪注释处理器</artifactId><version>0.0.3-SNAPSHOT</version></依赖></依赖项>

编辑 2:

经过进一步调查,我决定反编译处理器 JAR(使用 Maven 构建),结果……我的类不在那里.由于某些原因,Maven 没有将我的类编译到 JAR 中,这就是找不到这些类的原因.我试图找出该构建的问题(这在我之前从未发生过,而且我已经使用 Maven 有一段时间了......).

首先,那个项目的包装是jar.这些类都在 src/main/java 下.我已经在我的 pom.xml 中检查了类路径和源路径是相同的.

这是处理器 pom:

<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>co.aurasphere</groupId><artifactId>左轮手枪注释处理器</artifactId><version>0.0.3-SNAPSHOT</version><构建><插件><插件><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><配置><source>1.7</source><目标>1.7</目标></配置></插件></plugins></build><依赖项><!-- https://mvnrepository.com/artifact/javax.inject/javax.inject --><依赖><groupId>javax.inject</groupId><artifactId>javax.inject</artifactId><版本>1</版本></依赖><!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity --><依赖><groupId>org.apache.velocity</groupId><artifactId>速度</artifactId><version>1.7</version></依赖></依赖项>

编辑 3

和 .

由于项目最初是作为Eclipse简单的Java项目创建的,然后转换为Maven项目,我尝试创建一个新的Maven项目并将所有内容移到新项目中,希望问题是Eclipse插件搞砸了出了点问题,但错误仍然存​​在.

解决方案

我自己找到了答案.我发现问题出在 META-INF/services/中的文件 javax.annotation.processing.Processor 和注释处理器类的配置中.为了解决这个问题,我必须将以下内容添加到我的处理器项目的 pom.xml 配置中:

<插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.5.1</version><配置><编译器参数>-过程:无</compilerArgument><source>1.7</source><目标>1.7</目标></配置></插件></plugins></build>

这让 Maven 将类构建到实际的 jar 中并修复了问题.我不知道这是否是一个错误,但对我来说肯定看起来很奇怪.谢谢大家的帮助!

I'm new to annotation processing and I'm trying to automating it with Maven. I've put this in my pom.xml:

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <annotationProcessors>
                    <annotationProcessor>
                        co.aurasphere.revolver.annotation.processor.InjectAnnotationProcessor</annotationProcessor>
                    <annotationProcessor>
                        co.aurasphere.revolver.annotation.processor.RevolverContextAnnotationProcessor</annotationProcessor>
                </annotationProcessors>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>

The problem is that when I try to build the project I get a CompilationFailureException because Maven can't find the processors.

I've found other questions like this, solved by putting the dependency outside the plugin. I tried that, but nothing changed for me.

Am I missing something?

Thank you.

EDIT

Here is my dependency on another project which contains both the processor and the annotations:

    <dependencies>
    <dependency>
        <groupId>co.aurasphere</groupId>
        <artifactId>revolver-annotation-processor</artifactId>
        <version>0.0.3-SNAPSHOT</version>
    </dependency>
</dependencies>

EDIT 2:

After further investigation, I decided to decompile the processor JAR (built with Maven) and it happens that... my classes are not there. For some reasons, Maven is not compiling my classes into the JAR and that's why the classes are not found. I've tried figuring out what's wrong on that build (this never happened to me before and I've used Maven for a while...).

First of all, the packaging on that project is jar. The classes are all under src/main/java. I've checked in my pom.xml that the classpath and source path is the same.

Here's the processor pom:

<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>co.aurasphere</groupId>
<artifactId>revolver-annotation-processor</artifactId>
<version>0.0.3-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins> 
</build>
<dependencies>
    <!-- https://mvnrepository.com/artifact/javax.inject/javax.inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity -->
    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>1.7</version>
    </dependency>


</dependencies>

EDIT 3

Here's the output of a maven clean install on the processor project. Unfortunately the output is too long and I had to post an external link even if I know it's not good.

EDIT 4

Here are some screenshots of my dependency hierarchy: and .

Since the project was originally created as an Eclipse simple Java project and then converted to a Maven one, I tried to create a new Maven project and move everything to the new one in the hope that the problem was the Eclipse plugin that messed something up, but the error was still there.

解决方案

I've found the answer myself. I've figured out that the problem was the file javax.annotation.processing.Processor in META-INF/services/ with the configuration of the annotation processor's class. In order to fix the problem I had to add the following to the pom.xml configuration of my processor project:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <compilerArgument>
                    -proc:none
                </compilerArgument>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

This let Maven build the classes into the actual jar and fixed the problem. I don't know if this is a bug or not but it surely looks strange to me. Thank you everybody for the help!

这篇关于找不到Maven注释处理处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆