简体   繁体   English

导入的Maven模块中的龙目岛

[英]Lombok in imported Maven Module

I have following maven structure: 我有以下行家结构:

parent-module
|-model-module
|-model-contributor-module

In model-module I have entities that annotated with @lombok.Data . model-module我具有以@lombok.Data注释的实体。 When I make mvn clean install on model-module everything is ok. 当我在model-module上进行mvn clean install ,一切正常。 Second inner module model-contributor-module contains model-module in dependencies. 第二个内部模块model-contributor-module model-module在依赖项中包含model-module When I try to do the same build on model-contributor-module , I receive an error cannot find symbol . 当我尝试在model-contributor-module上进行相同的构建时,收到错误, cannot find symbol

pom.xml for model-module : 用于model-module pom.xml

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>

And pom.xml for model-contributor-module : 还有pom.xml用于model-contributor-module

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>
.....
<pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.16.8.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
....
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.16.8.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>testDelombok</goal>
                        <goal>delombok</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

How to fix these compilation errors? 如何解决这些编译错误?

[ERROR] /Users/superuser/Documents/workspace/project/test/src/main/java/com/company/services/impl/MyServiceImpl.java:[291,65] cannot find symbol
[ERROR] symbol:   method getUserId()

Move that lombok dependency into the parent pom's dependencyManagement element so it can be inherited by the child modules. 将那个lombok依赖项移到父pom的dependencyManagement元素中,以便子模块可以继承它。 You have the plugin available in all modules, but it looks like the lombok dependency is only available in model-module. 您已经在所有模块中使用了该插件,但是看起来lombok依赖项仅在模型模块中可用。

<dependencyManagement>
  <dependencies>
   ...
   <dependency> 
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
   </dependency>
  </dependencies>
</dependencyManagement>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM