簡體   English   中英

Gradle 多項目構建:未找到插件

[英]Gradle Multi-Project Build: Plugin was not found

我有一個非常基本的多項目/多模塊 Gradle 構建用例。 我最終需要的結構並不比官方 Gradle 文檔中提出的用於聲明子項目之間的依賴關系更復雜。

在這里復制他們的文檔,我們有這個項目結構:

.
├── buildSrc
│   ...
├── api
│   ├── src
│   │   └──...
│   └── build.gradle
├── services
│   └── person-service
│       ├── src
│       │   └──...
│       └── build.gradle
├── shared
│   ├── src
│   │   └──...
│   └── build.gradle
└── settings.gradle

這些構建文件:

// settings.gradle
rootProject.name = 'dependencies-java'
include 'api', 'shared', 'services:person-service'

// buildSrc/src/main/groovy/myproject.java-conventions.gradle
plugins {
    id 'java'
}

group = 'com.example'
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation "junit:junit:4.13"
}

// api/build.gradle
plugins {
    id 'myproject.java-conventions'
}

dependencies {
    implementation project(':shared')
}
shared/build.gradle
plugins {
    id 'myproject.java-conventions'
}

// services/person-service/build.gradle
plugins {
    id 'myproject.java-conventions'
}

dependencies {
    implementation project(':shared')
    implementation project(':api')
}

但是,當我實際嘗試此操作並從項目根目錄運行gradle build ,出現以下錯誤:

Plugin [id: 'myproject.java-conventions'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)

只是為了踢球,我嘗試添加一個版本,但可以預見的是,Gradle 也同樣脾氣暴躁,並說它無法解決這個工件。 我究竟做錯了什么?

我的 Gradle 版本信息:

------------------------------------------------------------
Gradle 6.5.1
------------------------------------------------------------

Build time:   2020-06-30 06:32:47 UTC
Revision:     66bc713f7169626a7f0134bf452abde51550ea0a

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.8 (Oracle Corporation 11.0.8+10)
OS:           Windows 10 10.0 amd64

在我看來,您發現文檔有問題。

名為buildSrc/src/main/groovy/myproject.java-conventions.gradle聲明了所謂的預編譯腳本插件 為此,您必須在buildSrc項目中應用名為groovy-gradle-plugin (用於 Groovy 插件)的插件:

# buildSrc/build.gradle
plugins {
    id 'groovy-gradle-plugin'
}

在此之后,它應該能夠找到您的自定義myproject.java-conventions插件。 如果是這樣,您可以在Gradle 問題跟蹤器上創建一個問題,以建議他們將上述代碼段添加到項目依賴項文檔中的示例中。

我和你一樣開始,遇到了同樣的問題。 雖然 Bjorn 的答案可能適用於 Java,但對我來說它沒有解決問題(對於 kotlin 實現),因為它還需要repositories塊中的gradlePluginPortal()

因此,要添加到已接受的答案中,最適合我開始的方法就是為類型application運行./gradlew init任務。 另請參閱使用庫 Sample 構建 Java 應用程序的 gradle 文檔。 在這里,無論實現語言如何,您都應該始終獲得一個正在運行的多項目。

在我自己的 kotlin 應用程序(帶有用於 gradle 的 groovy dsl)中,這呈現了以下buildSrc/build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 */

plugins {
    // Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
    id 'groovy-gradle-plugin'
}

repositories {
    // Use the plugin portal to apply community plugins in convention plugins.
    gradlePluginPortal()
}

dependencies {
    implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72'
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM