How to resolve "Could not get unknown property 'shadow' for project of type org.gradle.api.Project."

744 Views Asked by At

plugin used : id 'com.github.johnrengelman.shadow' version '4.0.4'

Gradle : https://services.gradle.org/distributions/gradle-7.4.2-bin.zip

getting error :

A problem occurred evaluating root project 'iot-bulk-slice-worker'.
> Could not get unknown property 'shadow' for project of type org.gradle.api.Project.

for :

plugins {
    id 'com.github.johnrengelman.shadow' version '4.0.4'
    //id 'com.github.johnrengelman.shadow' version '7.1.1'


}



if (subproject.name in gradle.platforms) {
        subproject.publishing {
            publications {
                code(MavenPublication) { publication ->
                    publication.artifactId = gradle.platforms ['artifactName']
                    from components.java
                }
                shadow(MavenPublication) { publication ->
                    publication.artifactId ="${subproject.name}"
                    subproject.shadow.component(publication)
                }
            }
        }
    }
}
1

There are 1 best solutions below

1
Bjørn Vester On BEST ANSWER

It is still a little difficult to say without the complete build file. But I assume the subproject variable is exactly that - a subproject. In that case, you are configuring a publication on a subproject that uses the shadow extension from itself.

This means to shadow plugin has to be applied to the subproject. From the snippets, you are only applying it to the root project.

Could be something like this:

plugins {
    id 'com.github.johnrengelman.shadow' version '4.0.4' apply false // <-- Set to false if the root project does not itself need to be "shadowed". This still makes the plugin available on the build classpath for subprojects.
}

subprojects { subproject ->
    if (...) {
        subproject.apply(plugin: 'com.github.johnrengelman.shadow')
        // publications here...
    }
}