javagradlegradle-pluginbuildconfig

java lib using BuildConfig plugin failed to compile using gradle 7.0.2 (Configuration <compile> not found)


Since I upgraded Gradle, my java lib won't compile with buildconfig plugin. Here is the 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'
}

It fails during Sync and here is the exception :

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.access$400(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




If I remove this plugin, the Sync works fine (but the project won't compile since I use BuildConfig of course).

Do someone meet the same problem and has an idea how to deal with it ?
(buildConfigField works only in android environment i believe, and this is not dedicated to android projects)


Solution

  • I've found a workaround, that seems to be working. I've just created an empty compile configuration.

    configurations {
        create("compile")
    }
    

    If you will got error like:

    Execution failed for task ':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.

    can be solved by:

    tasks {
        withType<Jar> {
            duplicatesStrategy = DuplicatesStrategy.INCLUDE
        }
    }