我正在努力使用一个简单的 gradle 构建脚本来添加 Lombok Project我的项目的功能(生成访问器方法)通过 gradle-lombok plugin 。使用 gradle 我无法通过命令行构建它,它无法编译。我创建了this small project作为概念证明来表明它不起作用。请参阅下面的我的脚本和未编译的类。
之后我重新创建了 project with sub-projects structure最奇怪的是,仅仅进行这种分离就可以使其工作,但我仍在寻找为什么单个项目不起作用。
如果有人能给出提示,我们将非常欢迎。
buildscript {
repositories {
jcenter()
mavenLocal()
maven { url "https://repo.spring.io/plugins-release" }
maven { url "https://plugins.gradle.org/m2" }
}
dependencies {
classpath "io.franzbecker:gradle-lombok:1.7"
}
}
plugins {
id "io.franzbecker.gradle-lombok" version "1.7"
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: "io.franzbecker.gradle-lombok"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
group = 'lombok-demo'
version = '1.0-SNAPSHOT'
buildDir = 'target'
// global configurations
configurations {
compile {
exclude(module: 'commons-logging')
exclude(module: 'c3p0')
exclude(module: 'log4j')
exclude(module: 'log4j2')
exclude(module: 'opensaml')
}
}
repositories {
mavenLocal()
mavenCentral()
maven { url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/" }
maven { url "http://jasperreports.sourceforge.net/maven2/"}
}
dependencies {
compile "com.google.guava:guava:${version_guava}"
compile "org.projectlombok:lombok:1.16.10"
compile "org.slf4j:slf4j-api:${version_slf4j}"
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
compile "javax.validation:validation-api:${version_javax_validation}"
compile ("org.hibernate:hibernate-validator:${version_hibernate_validator}") {
exclude(module: "classmate")
}
compile group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.3.0'
compile "org.hsqldb:hsqldb:${version_hsqldb}"
//provided "org.hsqldb:hsqldb:${version_hsqldb}"
}
tasks.withType( JavaCompile.class ).all { task ->
task.options.encoding = "UTF-8"
task.options.compilerArgs += ["-nowarn", "-proc:none", "-encoding", "UTF-8", "-source", sourceCompatibility, "-target", targetCompatibility ]
}
@Data
@Entity
public class Invoice {
private Long id;
private String invoiceNumber;
private LocalDateTime issueDate;
private Customer customer;
private LocalDateTime startDate;
private LocalDateTime endDate;
private Address billingAddress;
private List<InvoiceItem> items;
public Invoice() {
this.issueDate = LocalDateTime.now();
this.billingAddress = customer.getMailingAddress();
this.items = new ArrayList<>();
}
public Invoice(Customer customer) {
this();
this.customer = customer;
}
}
import lombok.Data;
import lombokdemo.domain.Address;
import lombokdemo.domain.Customer;
import lombokdemo.domain.Invoice;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
@Data
public class Header {
private final DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
private String companyName;
private Address companyAddress;
private URL companyLogo;
private Invoice invoice;
private Customer customer;
private LocalDateTime issueDate;
private LocalDateTime startDate;
private LocalDateTime endDate;
private Address billingAddress;
public Header(Invoice invoice) {
this.invoice = invoice;
this.issueDate = LocalDateTime.now();
this.companyName = "";
this.companyAddress = new Address();
}
public String getInvoiceNumber() {
return invoice.getInvoiceNumber();
}
public String getIssueDateText() { return dateFormat.format(issueDate); }
public String getPeriod() {
return dateFormat.format(startDate) + " to " + dateFormat.format(endDate);
}
public String getCustomerName() {
return invoice.getCustomer().getName();
}
private String getAddressText(Address address, boolean includingWeb) {
StringBuilder sb = new StringBuilder();
sb.append(address.getStreet1());
if (!address.getStreet2().isEmpty()) {
sb.append("\n").append(address.getStreet2());
}
if (sb.length() > 0) {
sb.append("\n");
}
if (address.getCity() != null && !address.getCity().isEmpty()) {
sb.append(address.getCity());
if (!address.getStateOrProvince().isEmpty()) {
sb.append(", ").append(address.getStateOrProvince());
}
if (!address.getPostalCode().isEmpty()) {
sb.append(" ").append(address.getPostalCode());
}
sb.append("\n");
}
if (address.getCountry() != null && !address.getCountry().isEmpty()) {
sb.append(address.getCountry());
sb.append("\n");
}
if (includingWeb) {
if (!address.getWebsite().isEmpty()) {
sb.append(address.getWebsite());
sb.append("\n");
}
if (!address.getEmail().isEmpty()) {
sb.append(address.getEmail());
sb.append("\n");
}
}
return sb.toString();
}
public String getCompanyAddress() {
final StringBuilder sb = new StringBuilder();
if (!companyAddress.getContactName().isEmpty()) {
sb.append(companyAddress.getContactName());
}
sb.append(companyAddress.getStreet1());
if (!companyAddress.getStreet2().isEmpty()) {
sb.append("\n").append(companyAddress.getStreet2());
}
sb.append("\n");
sb.append(getAddressText(companyAddress, true));
return sb.toString();
}
public String getBillingAddress() {
final Address address = invoice.getCustomer().getMailingAddress();
final StringBuilder sb = new StringBuilder();
if (!address.getContactName().isEmpty()) {
sb.append(address.getContactName());
}
sb.append(getAddressText(address, false));
return sb.toString();
}
}
最佳答案
问题来自-proc:none
。 documentation说“-proc:none 意味着编译无需注释处理”,并且 lombok 需要注释处理来生成所有附加方法。
关于java - gradle-lombok 插件无法在单个项目中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39609120/