java 使用 BuildConfig 插件的库无法使用 gradle 7.0.2 编译(未找到配置 <compile>)
java lib using BuildConfig plugin failed to compile using gradle 7.0.2 (Configuration <compile> not found)
自从我升级了 Gradle,我的 java 库将无法使用 buildconfig 插件进行编译。
这是 build.gradle(:driver-java)
plugins {
id 'java-library' // Pure Java
id 'de.fuerstenau.buildconfig' version '1.1.8' // BuildConfig
}
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
//project.name = "MyProject"
project.version = "0.9.7"
sourceSets.main.resources.srcDirs = [ "resources/" ]
tasks.named('jar') {
manifest {
attributes(
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Main-Class': 'com.texisense.driver.java.TxDriverTryMe'
)
}
}
dependencies {
implementation group: 'com.fazecast', name: 'jSerialComm', version: '2.5.2'
}
它在同步期间失败,这里是例外情况:
A problem occurred configuring project ':driver-java'.
> Configuration <compile> not found.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':driver-java'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access0(LifecycleProjectEvaluator.java:51)
(...)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin.getCompileConfiguration(BuildConfigPlugin.groovy:77)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin$_apply_closure3$_closure6.doCall(BuildConfigPlugin.groovy:159)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin$_apply_closure3.doCall(BuildConfigPlugin.groovy:157)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
(...)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:155)
at org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal$getByName.call(Unknown Source)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin.getCompileConfiguration(BuildConfigPlugin.groovy:73)
... 171 more
如果我删除这个插件,Sync 工作正常(但项目不会编译,因为我当然使用 BuildConfig)。
有人遇到同样的问题并且知道如何处理吗?
(我相信 buildConfigField 只能在 android 环境中工作,并且这不适用于 android 项目)
我找到了一种解决方法,似乎有效。我刚刚创建了一个空的编译配置。
configurations {
create("compile")
}
如果你会得到这样的错误:
任务“:jar”执行失败。
Entry com/fiftytwo/vim/BuildConfig.class is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
可以通过以下方式解决:
tasks {
withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
自从我升级了 Gradle,我的 java 库将无法使用 buildconfig 插件进行编译。
这是 build.gradle(:driver-java)
plugins {
id 'java-library' // Pure Java
id 'de.fuerstenau.buildconfig' version '1.1.8' // BuildConfig
}
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
//project.name = "MyProject"
project.version = "0.9.7"
sourceSets.main.resources.srcDirs = [ "resources/" ]
tasks.named('jar') {
manifest {
attributes(
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Main-Class': 'com.texisense.driver.java.TxDriverTryMe'
)
}
}
dependencies {
implementation group: 'com.fazecast', name: 'jSerialComm', version: '2.5.2'
}
它在同步期间失败,这里是例外情况:
A problem occurred configuring project ':driver-java'.
> Configuration <compile> not found.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':driver-java'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access0(LifecycleProjectEvaluator.java:51)
(...)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin.getCompileConfiguration(BuildConfigPlugin.groovy:77)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin$_apply_closure3$_closure6.doCall(BuildConfigPlugin.groovy:159)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin$_apply_closure3.doCall(BuildConfigPlugin.groovy:157)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
(...)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.getByName(DefaultConfigurationContainer.java:155)
at org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal$getByName.call(Unknown Source)
at de.fuerstenau.gradle.buildconfig.BuildConfigPlugin.getCompileConfiguration(BuildConfigPlugin.groovy:73)
... 171 more
如果我删除这个插件,Sync 工作正常(但项目不会编译,因为我当然使用 BuildConfig)。
有人遇到同样的问题并且知道如何处理吗?
(我相信 buildConfigField 只能在 android 环境中工作,并且这不适用于 android 项目)
我找到了一种解决方法,似乎有效。我刚刚创建了一个空的编译配置。
configurations {
create("compile")
}
如果你会得到这样的错误:
任务“:jar”执行失败。
Entry com/fiftytwo/vim/BuildConfig.class is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
可以通过以下方式解决:
tasks {
withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}