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

标签 gradle gradle-plugin

我试图创建一个像这样设置的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>

关于gradle - 麻烦的Gradle插件项目与第三方Maven存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63963334/

相关文章:

gradle - 使用Gradle和Kotlin DSL配置Jacoco

gradle - 使用Maven项目作为Gradle源依赖项的Git存储库

java - 远程调试tomcat时Intellij断点不命中

Android Studio maven { url "https://jitpack.io"} 无法下载

macos - Gradle在Mac中为JAVA_HOME获取错误的值

java - spring-boot-gradle-plugin 是否随 spring-boot 版本一起移动?

jdbc - DriverManager 在 gradle 自定义插件的任务中看不到依赖项

android-gradle-plugin - Android插件过旧(2.4.0-alpha7)

android - Android Gradle找不到远程AAR

intellij-idea - IntelliJ在复制任务中将导入添加到Gradle