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

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

问题描述

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

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>

问题是,当我尝试构建项目时,由于Maven找不到处理器,所以我收到CompilationFailureException.

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.

我想念什么吗?

谢谢.

编辑

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

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>

编辑2 :

经过进一步研究,我决定反编译处理器JAR(使用Maven构建),并且碰巧...我的类不在那里.由于某些原因,Maven没有将我的类编译到JAR中,这就是为什么找不到这些类的原因.我已经尝试找出该版本的问题(以前从未发生过这种情况,而我已经使用Maven了一段时间……).

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...).

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

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.

这是处理器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>

编辑3

此处是处理器项目上maven全新安装的输出.不幸的是,输出太长,即使我知道效果不好,我也不得不发布一个外部链接.

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.

编辑4

以下是我的依赖项层次结构的一些屏幕截图:和.

Here are some screenshots of my dependency hierarchy: and .

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

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.

推荐答案

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

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>

这使Maven将类构建到实际的jar中并解决了问题.我不知道这是否是错误,但对我来说确实很奇怪.谢谢大家的帮助!

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天全站免登陆