简体   繁体   中英

How to build a Gradle plugin project together with a subproject that uses it?

I have a Gradle project with several modules among which I have a module implementing a Gradle plugin ( plugin-subproject ) and a module with a showcase of this plugin ( sample-subproject ):

plugin-subproject
│   build.gradle
sample-subproject
│   build.gradle
other subprojects...
│   build.gradle   
build.gradle

In the sample-subproject , I have a dependency on the plugin:

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath "myplugin:gradle-plugin:0.1.0"
    }
}

apply plugin: "myplugin.plugin"

It has to take the plugin from the local repository.

Problem: In order to build the sample-subproject , the plugin has to be installed into local Maven repository. But I cannot install it because if I run ./gradlew:plugin-subproject:install it fails.

* What went wrong:
A problem occurred configuring project ':sample-subproject'.
> Could not resolve all artifacts for configuration ':sample-subproject:classpath'.
> Could not find myplugin:gradle-plugin:0.1.0.
    Searched in the following locations:
    - https://repo.maven.apache.org/maven2/myplugin/gradle-plugin/0.1.0/gradle-plugin-0.1.0.pom
    - file:/Users/myuser/.m2/repository/myplugin/gradle-plugin/0.1.0/gradle-plugin-0.1.0.pom
    - https://plugins.gradle.org/m2/myplugin/gradle-plugin/0.1.0/gradle-plugin-0.1.0.pom
    Required by:
        project :sample-subproject

I can remove the sample-subproject , install the plugin to the local maven repository and then I can successfully add and build the sample project. But it is a hack, I want to solve the issue in a standard way.

Question: How can I build a Gradle plugin project together with a subproject that uses it?

Your can add line in main build.gradle :

build.dependsOn ":plugin-subproject:build"

PS There is way to define modules in settings.gradle

rootProject.name = 'project-name'

include "plugin-subproject"
include "sample-subproject"
include "other subprojects"

and make dependencies like this:

dependencies {
    implementation project(':plugin-subproject')
}

but there is no documentary evidence that this is the correct way to do the correct order of assembling modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM