1. 程式人生 > >使用lombok 註解Java類

使用lombok 註解Java類

config -s intel 16px ogg all prop 安裝 end

環境信息:

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. [email protected],根據註解生成的方法沒有在outline中顯示, 以及無法在代碼編輯是resolve註解生成的方法

解決: 添加lombok-plugin

參考: https://stackoverflow.com/questions/41161076/adding-lombok-plugin-to-intellij-project

使用lombok 註解Java類