我有兩個gradle這個文件的項目:build.gradle
和myPlugin.gradle
如何將Gradle Plugin(及其依賴)加載到build.gradle中?
的myPlugin.gradle
實現的插件接口。該插件還對osdetector-gradle-plugin
我加了對方旁邊兩個gradle這個文件的依賴性,然後我試圖申請爲myplugin爲build.gradle
如下:
apply from: 'myPlugin.gradle'
不過,我有以下錯誤myPlugin.gradle
文件:
Plugin with id 'com.google.osdetector' not found
這裏是myPlugin.gradle
文件的代碼:
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)
在build.gradle
文件:我只是做這樣的事情:
//定義buildScript庫和依賴然後
apply from: 'myPlugin.gradle'
task dummy{
println HostingMachineOS.isMacOS()
println HostingMachineOS.isLinux()
println HostingMachineOS.isWindows()
}
我怎樣才能解決這個插件ID爲「com.google.osdetector」不發現了什麼?
聽起來像是你的'myPlugin.gradle'找不到插件ID爲' com.google.osdetector',也許你應該在'myPlugin.gradle'中添加一個buildscript部分(帶有適當的倉庫部分)? – RaGe
我在myPlugin.gradle中添加了buildscript部分,但仍然有相同的錯誤?主build.gradle和myPlugin.gradle之間的依賴關係是否存在關係? –