Home > Net >  Could not get unknown property 'plugin' for project ':lib' of type org.gradle.ap
Could not get unknown property 'plugin' for project ':lib' of type org.gradle.ap

Time:06-15

Java 11 and Gradle 7.2 here. I am trying to build a reusable library that I can (eventually) publish to a Maven repository and pull into other projects. But first I just want to get it publishing to my local m2 repo.

The project directory structure looks like:

mylib/
  lib/
    src/
    build.gradle

Where build.gradle is:

plugins {
    id 'java-library'
}

apply plugin 'maven-publish'

sourceCompatibility = 1.11
targetCompatibility = 1.11
version = '1.0.0-RC1'
group = 'com.example'

repositories {
    mavenCentral()
}

dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'

    compileOnly 'org.projectlombok:lombok:1.18.24'

    // dependencies that are used internally, and not exposed to consumers on their own compile classpath
    implementation (
        'net.sf.dozer:dozer:5.5.1'
    )

    testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
}

publishing {
    publications {
        maven(MavenPublication) {
            artifact("build/libs/mylib-${version}.jar") {
                extension 'jar'
            }
        }
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

When I run gradle publishToMavenLocal I get:

% ./gradlew publishToMavenLocal       

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/myuser/workspace/mylib/lib/build.gradle' line: 5

* What went wrong:
A problem occurred evaluating project ':lib'.
> Could not get unknown property 'plugin' for project ':lib' of type org.gradle.api.Project.

Any idea what's going wrong here?

CodePudding user response:

Try placing your plugins in this way. Not sure if that resolves your issue though.

plugins {
    id 'java-library'
    id 'maven-publish'
}

CodePudding user response:

You're mixing the plugins DSL (plugins { }) with legacy plugin application (apply plugin). That's not a big deal, but you should go with @sean's answer and use the plugins DSL instead which will solve your issue.

To your problem at hand

Could not get unknown property 'plugin'

That happens because you missed the : in apply plugin

apply plugin: 'maven-publish'
  • Related