首页 > 代码库 > 使用lombok 注解Java类
使用lombok 注解Java类
环境信息:
IDEA 2016.2.4
Maven 3
JDK 1.8
Maven工程配置:
<properties> <lombok.version>1.16.16</lombok.version> <lombok.plugin.version>1.16.16.0</lombok.plugin.version> </properties> <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>${lombok.plugin.version}</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </pluginManagement> </build>
安装lombok插件:
1. 下载 https://plugins.jetbrains.com/plugin/6317-lombok-plugin
2. Setting -> plugins ->install plugin from disk
3. Setting->Build,Exe... -> Compiler->Annotation Processors -> 勾选enable annotation processing
遇到的问题:
1. The parameters ‘encoding‘ for goal org.projectlombok:lombok-maven-plugin:1.16.16.0:delombok are missing or invalid
根据 , 缺少encoding参数 在pom中添加如下属性:
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2. 添加@Data注解后,根据注解生成的方法没有在outline中显示, 以及无法在代码编辑是resolve注解生成的方法
解决: 添加lombok-plugin
参考: https://stackoverflow.com/questions/41161076/adding-lombok-plugin-to-intellij-project
使用lombok 注解Java类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。