簡體   English   中英

Maven-Pom中的Mapstruct和其他注釋處理器

[英]Mapstruct together with other annotation-processors in maven-pom

http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0

<artifactId>yyy-data</artifactId>
<name>VS yyy (data)</name>

<parent>
    <groupId>de.xxx</groupId>
    <artifactId>yyy-server</artifactId>
    <version>8.1.0-SNAPSHOT</version>
</parent>
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <distribution.outputDirectory>${project.build.directory}/dist</distribution.outputDirectory>
</properties>

<dependencies>

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.8</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.2.8-b01</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.8-b01</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>1.3.0.Final</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>1.3.0.Final</version>
                    </path>
                </annotationProcessorPaths>
                <annotationProcessors>
                    <annotationProcessor>de.zzz.annotation.processor.GenerateHibernateTypeForEnumProcessor</annotationProcessor>
                    <annotationProcessor>de.zzz.annotation.processor.GenerateHibernateTypeForWertelistenProcessor</annotationProcessor>
                    <annotationProcessor>de.zzz.annotation.processor.BusinessObjectAnnotationProcessor</annotationProcessor>
                    <annotationProcessor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</annotationProcessor>
                </annotationProcessors>
            </configuration>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>m2e</id>
        <activation>
            <property>
                <name>m2e.version</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin> 
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

親愛的大家,

在我的project中實施mapstruct ,我需要一些幫助。 我已經有一些注釋處理器,需要在maven的pom.xml中命名。 Mapstruct建議在pom.xml中添加annotationProcessorPaths Mapstruct 似乎不可能在同一pom中同時使用這兩個批注( annotationProcessorPathsannotationProcessor )。 如果這樣做,我會得到錯誤

無法在項目yyy數據上執行目標org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile(默認):編譯失敗[ERROR]注釋處理器'de.zzz.annotation.processor.GenerateHibernateTypeForEnumProcessor'未找到

我確實縮短了pom。 因此,可能存在比實際需要更多的依賴關系。

在此先感謝Oliver

您仍然可以使用annotationProcessor 您將需要添加mapstruct-processor在你的依賴,然后添加org.mapstruct.ap.MappingProcessorannotationProcessor

為什么你看到的錯誤的原因是因為當你定義annotationProcessorPathsmaven-compiler-plugin將只使用那些尋找注解處理器,而不是你的其他依賴。

另外,您還可以添加您在擁有所有的注解處理器annotationProcessoPaths ,而不是如果你的依賴。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM