我有一个有两个 gradle 文件的项目:build.gradle
and myPlugin.gradle
The myPlugin.gradle
实现了插件接口。该插件还依赖于osDetector-gradle-插件
我将两个 gradle 文件并排添加,然后尝试将 myPlugin 应用到build.gradle
如下:
apply from: 'myPlugin.gradle'
但是,我遇到了以下错误myPlugin.gradle
file:
Plugin with id 'com.google.osdetector' not found
这是代码myPlugin.gradle
file:
apply plugin: 'groovy'
apply plugin: 'maven'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
}
import org.gradle.api.tasks.TaskAction
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
apply plugin: 'com.google.osdetector'
apply plugin: HostingMachineOSPlugin
class HostingMachineOSPlugin implements Plugin<Project>{
void apply(Project project){
project.plugins.apply("com.google.osdetector");
//project.configurations.files('com.google.osdetector')
println project.osdetector.os
/* Extend the project property to have the class HostingMachineOS */
project.ext.HostingMachineOS = HostingMachineOS
}
}
public class HostingMachineOS {
static family = "Unkown"
static def setFamilyName(name){
family = name
}
static def isLinux (){
family == "linux"
}
static def isWindows (){
family == "windows"
}
static def isMacOS(){
family == "osx"
}
}
HostingMachineOS.setFamilyName(osdetector.os)
in build.gradle
文件:我只是在做这样的事情:
//然后定义buildScript存储库和依赖项
apply from: 'myPlugin.gradle'
task dummy{
println HostingMachineOS.isMacOS()
println HostingMachineOS.isLinux()
println HostingMachineOS.isWindows()
}
如何解决找不到 id 'com.google.osdetector' 的插件的问题?