2

我有以下 build.gradle 文件:

plugins {
    id 'maven-publish'
    id 'java-platform'
}
subprojects {
    configurations {
        deployerJars
    }

    apply plugin: 'java'
    apply plugin: 'java-library'
}
publishing {
    publications {
        myPlatform(MavenPublication) {
            from components.javaPlatform
        }
    }
}

我收到了那个错误:

> Could not get unknown property 'javaPlatform' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

找不到有关此错误的任何信息,并且根据我从平台插件页面的了解,您无法将带有“java”插件的项目设置为“java-platform”插件,但事实并非如此。我很感激这里的一些指导,谢谢。

4

1 回答 1

3

publications必须在publishing块内。而且您不能使用from components.java,因为您的项目不是 Java 项目,而是一个平台。所以应该是

plugins {
    id 'maven-publish'
    id 'java-platform'
}
subprojects {
    configurations {
        deployerJars
    }

    apply plugin: 'java'
    apply plugin: 'java-library'
}
publishing {
    publications {
        myPlatform(MavenPublication) {
            from components.javaPlatform
        }
    }
}
于 2019-12-15T16:19:25.727 回答