我有两个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之间的依赖关系是否存在关系? –