麻烦的Gradle插件项目与第三方Maven存储库

问题描述

我正在尝试创建一个像这样设置的Gradle插件

plugins {
    id 'java-gradle-plugin'
    id 'groovy'
}

repositories {
    mavenCentral()
    jcenter()
    // note the custom maven repo
    maven { url = "https://maven.gentics.com/maven2" }
}

dependencies {
    implementation gradleApi(),localGroovy(),"com.gentics.mesh:mesh-rest-client:${MESH_VER}" 
    testImplementation gradleTestKit()
    testImplementation("org.spockframework:spock-core:${SPOCK_VER}") {
        exclude module : 'groovy-all'
    }
}
// the rest...

但是,如果我尝试在includeBuild "./gradle-mesh"中使用settings.gradle的另一个项目中使用此插件,则会出现以下错误

A problem occurred configuring root project 'functionalTest'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.gentics.mesh:mesh-rest-client:1.7.1.
    Searched in the following locations:
    - https://plugins.gradle.org/m2/com/gentics/mesh/mesh-rest-client/1.7.1/mesh-rest-client-1.7.1.pom
    If the artifact you are trying to retrieve can be found in the repository but without Metadata in 'Maven POM' format,you need to adjust the 'MetadataSources { ... }' of the repository declaration.
    required by:
        project : > project :gradle-mesh

但是,我能够在实际的插件测试中执行functionalTest而没有问题。删除settings.gradle中的该行并将文件重命名buildSrc也可以。

是否可以从插件入口点配置buildscript依赖项?我尝试了以下方法,但没有任何区别。

class GradleMeshPlugin implements Plugin<Project> {
    public void apply(Project project) {
        project.buildscript.repositories.configure {
            mavenLocal()
            jcenter()
            maven { url = "https://maven.gentics.com/maven2" }
        }
        
        // dependency is referenced here...
    }
}

任何想法如何解决

完整项目:https://github.com/wawebio/gradle-mesh

系统:

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------

Build time:   2020-08-25 16:29:12 UTC
Revision:     f2d1fb54a951d8b11d25748e4711bec8d128d7e3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.8 (Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OS:           Linux 5.4.0-47-generic amd64

更新 通过在消耗项目的settings.gradle

添加以下内容,我也能够使其工作
pluginManagement {
    repositories {
        mavenCentral()
        jcenter()
        maven { url = "https://maven.gentics.com/maven2" }
    }
}

rootProject.name = 'website'

includeBuild "./gradle-mesh"

有没有办法从插件应用程序内部执行此操作?

解决方法

您需要以其他方式指定mvn软件包,这是第一个。

<configuring-project>