Plugins 编写具有非传递依赖项的自定义gradle插件

Plugins 编写具有非传递依赖项的自定义gradle插件,plugins,gradle,Plugins,Gradle,我正在尝试实现一个gradle插件,它反过来又依赖于另一个gradle插件。这是我的插件build.gradle的一个片段 buildscript { repositories { mavenCentral() mavenLocal() } } apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'maven' dependencies { repositories { maven

我正在尝试实现一个gradle插件,它反过来又依赖于另一个gradle插件。这是我的插件build.gradle的一个片段

buildscript {
  repositories {
    mavenCentral()
    mavenLocal()
  }
}

apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'

dependencies {
    repositories {
        mavenCentral()
        mavenLocal()
    }

    compile gradleApi()
    compile localGroovy()
    compile 'com.example:otherplugin:[0.1,)'
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: mavenLocal())
            pom.groupId = 'com.example'
            pom.version = '0.5'
            pom.artifactId = 'myplugin'
        }
    }
}
正如您所看到的,我使用的是范围依赖性,对任何版本的'otherplugin'都不挑剔。当用户在其build.gradle中包含我的插件时:

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'com.example:otherplugin:1.0', 'com.example:myplugin:2.3'
    }
}
Gradle总是使用最新版本的'com.example:otherplugin'来处理他的项目。理想情况下,我希望下载用户指定的版本,并由gradle使用


我相信这是我的插件build.gradle的一个问题。我如何修改插件的build.gradle以避免这种可传递的依赖关系?

用户将能够以正常方式强制转换插件版本(例如
buildscript{configurations.classpath.resolutionStrategy.force(“com.example:otherplugin:0.3”)
)。@PeterNiederwieser谢谢,这很有效!这就是答案!谢谢