我正在尝试将groovy添加到利用Lombok的现有Java Maven项目中.不幸的是,当我使用下面的pom片段启用groovy-maven-eclipse编译器时,我的lombok注释的java文件无法编译.据我所知,Lombok根本没有参与java文件的编译.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.6.0-01-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我还应该指出,在eclipse中(使用m2e)一切正常.当我尝试做一个mvn包时,我的问题出现了.
我想在项目中使用Lombok来使用@Getter和@Setter.
我包括使用Maven:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.12.6</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Netbeans导入正常:
import lombok.Getter;
import lombok.Setter;
Run Code Online (Sandbox Code Playgroud)
但是自动设置器和getter不起作用(没有自动完成/"找不到符号......").
奇怪的是,对于另一个项目,我有它的工作正常!但我无法弄清楚这些差异.
我测试过:
更改lombok版本(甚至是最后一个):对于任何版本,导入都不再起作用
用Maven构建项目:没关系!
使用Eclipse:没关系!(但不幸的是,我是唯一一个决定的人)
=>所以我确定这是一个与Netbeans相关的问题
任何的想法 ?
有没有人将Lombok 1.16与Dagger2一起使用?
我当前的代码如下:
@AllArgsConstructor(onConstructor = @__(@Inject))
public class JuiceMaker {
private final Apple apple;
Run Code Online (Sandbox Code Playgroud)
错误是:
JuiceMaker cannot be provided without an @Inject constructor or from an @Provides-annotated method.
Run Code Online (Sandbox Code Playgroud)
如果没有Lombok批注,这实际上可以工作,因此:
public class JuiceMaker {
private final Apple apple;
@Inject
public JuiceMaker(Apple apple){
this.apple = apple
}
}
Run Code Online (Sandbox Code Playgroud)
作品
我有一个 maven 多模块项目,其中包含一个父模块和三个子模块。该应用程序使用弹簧引导。在其中一个子模块中,我有 SpringBootApplication:
@SpringBootApplication
@EnableConfigurationProperties({AppProperties.class})
public class MainSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MainSpringBootApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
应用属性在同一个模块中:
@Data
@ConfigurationProperties(prefix = "asdf")
public class AppProperties {
...
}
Run Code Online (Sandbox Code Playgroud)
在该模块的 pom.xml 中有一个 spring-boot-configuration-processor 的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当我在父项目上运行 mvn install 时,未创建此子模块中的 target/classes/META-INF/spring-configuration-metadata.json 文件。当我修改该子模块的 pom 以直接继承时:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Run Code Online (Sandbox Code Playgroud)
直接在子模块上做mvn install,生成target/classes/META-INF/spring-configuration-metadata.json文件。
你有什么提示吗?