4

テックスタックテーマと連動動作していない:MapStructとロンボクが使用されて

のJava 8 MapStruct:1.2.0.Final ロンボク:1.16.18 IDE:IntelliJの - ロンボクプラグインはすでに最初

  • をインストール私はgetterとsetterを削除したときに問題に直面し、@Getter@Setterという注釈を追加しました。
  • 私はロンボクを知りましたMapStruct 1.2.0.Beta1以降の1.16.14以降は互換性があり、一緒に動作することができますが、私のバージョンは新しいものであり、問​​題はまだ発生しています。
  • 私がすでに試したもう一つの解決策は、LombokのDelombokプラグインを実行することですが、同じ問題が発生しています。以下は

プロジェクトファイルです:

エンティティ・オブジェクト: One.java

import lombok.Getter; 
import lombok.Setter; 

@Getter 
@Setter 
public class One { 

    private int id; 
    private Integer version; 
    private int projectId; 
    private String title; 
    private String code; 
    private int sortOrder; 

} 

DTOオブジェクト:OneDTO.java

import lombok.Getter; 
import lombok.Setter; 

@Getter 
@Setter 
public class OneDto { 

    private int id; 
    private Integer version; 
    private int projectId; 
    private String title; 
    private String code; 
    private int sortOrder; 

} 

Mapperクラス:OneMapper.java

import org.mapstruct.Mapper; 
import org.mapstruct.Mapping; 

import com.vg.once.dto.OneDto; 
import com.vg.once.entity.One; 

@Mapper 
public interface OneMapper { 

    @Mapping(target="id", source="one.id") 
    OneDto createOne (One one); 

} 

のpom.xml

<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>com.vg</groupId> 
    <artifactId>mapstruct</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>Mapstruct-test</name> 

    <properties> 
     <java.version>1.8</java.version> 
     <org.mapstruct.version>1.2.0.Final</org.mapstruct.version> 
     <org.projectlombok.version>1.16.18</org.projectlombok.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.projectlombok</groupId> 
      <artifactId>lombok</artifactId> 
      <version>${org.projectlombok.version}</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.mapstruct</groupId> 
      <artifactId>mapstruct-jdk8</artifactId> 
      <version>${org.mapstruct.version}</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
     <plugin> 
       <groupId>org.projectlombok</groupId> 
       <artifactId>lombok-maven-plugin</artifactId> 
       <version>1.16.18.1</version> 
       <executions> 
        <execution> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>delombok</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <sourceDirectory>src/main/java</sourceDirectory> 
        <addOutputDirectory>false</addOutputDirectory> 
        <outputDirectory>${project.build.directory}/delombok</outputDirectory> 
        <encoding>UTF-8</encoding> 
        <skip>false</skip> 
        <verbose>false</verbose> 
       </configuration> 
      </plugin>  
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.1</version> 
       <configuration> 
        <source>${java.version}</source> 
        <target>${java.version}</target> 
        <annotationProcessorPaths> 
         <path> 
          <groupId>org.mapstruct</groupId> 
          <artifactId>mapstruct-processor</artifactId> 
          <version>${org.mapstruct.version}</version> 
         </path> 
        </annotationProcessorPaths> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

ビルドトレース

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Mapstruct-test 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- lombok-maven-plugin:1.16.18.1:delombok (default) @ mapstruct --- 
[INFO] Delombok complete. 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mapstruct --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ mapstruct --- 
[INFO] Changes detected - recompiling the module! 
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! 
[INFO] Compiling 5 source files to /home/vivekgupta/Documents/workspaces/mapstruct-test/mapstruct/target/classes 
[INFO] ------------------------------------------------------------- 
[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] /home/vivekgupta/Documents/workspaces/mapstruct-test/mapstruct/src/main/java/com/vg/once/mapper/OneMapper.java:[12,9] Unknown property "id" in result type com.vg.once.dto.OneDto. Did you mean "null"? 
[INFO] 1 error 
[INFO] ------------------------------------------------------------- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.637 s 
[INFO] Finished at: 2017-12-06T19:23:53+05:30 
[INFO] Final Memory: 19M/235M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project mapstruct: Compilation failure 
[ERROR] /home/vivekgupta/Documents/workspaces/mapstruct-test/mapstruct/src/main/java/com/vg/once/mapper/OneMapper.java:[12,9] Unknown property "id" in result type com.vg.once.dto.OneDto. Did you mean "null"? 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

私は一緒にロンボクとMapStructの両方を使用してこの作業を取得することができますどのように共有してください!

答えて

3

MavenがLombokではなくMapStructプロセッサのみを使用するためです。 annotationProcessorPathsはどのプロセッサを使うべきかをmavenに伝えます。

delombokは、クラスごとに2つのファイルで終わるので、何もしません。私はmavenコンパイラがそれらを見ないと思います。

あなたは2つのオプションがあります:

オプション1:あなたの依存関係にmapstruct-processor依存関係を追加し、annotationProcessorPathsを削除

anootationProcessorPaths

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.6.1</version> 
    <configuration> 
     <source>${java.version}</source> 
     <target>${java.version}</target> 
     <annotationProcessorPaths> 
      <path> 
       <groupId>org.mapstruct</groupId> 
       <artifactId>mapstruct-processor</artifactId> 
       <version>${org.mapstruct.version}</version> 
      </path> 
      <path> 
       <groupId>org.projectlombok</groupId> 
       <artifactId>lombok</artifactId> 
       <version>${org.projectlombok.version}</version> 
      </path> 
     </annotationProcessorPaths> 
    </configuration> 
</plugin> 

オプション2にロンボク島の依存関係を追加します。このようにして、mavenコンパイラは依存関係にあるすべての注釈プロセッサを選択します。

オプション1を使用することをお勧めします。そうすれば、あなたのコードにいくつかのMapStruct推移的依存関係と内部クラスを使用していないことを確信できます。

編集:

IntelliJの注釈処理はまた、あなたがIDEA-150621によるprovided依存関係としてmapstruct-processorを追加する必要があります動作することを確認します。現時点でIntelliJはMavenのannotationProcessorPathsを使用してプロジェクトを正しく設定していません。

関連する問題