我有一个名为
MyPlugin
的自定义插件,其中包含一个名为MyTask
的自定义任务。我想让MyTask
依赖于compileJava
。我尝试给MyTask.dependsOn(compileJava)
,但它说不存在名为'MyTask'的任务
。有没有办法做到这一点?
MyPlugin.java
public class MyPlugin implements Plugin<Project> {
public static final String TASK_NAME = "MyTask";
@Override
public void apply(Project project) {
project.getExtensions().create(TASK_NAME, MyExtension.class);
project.getTasks().create(TASK_NAME, MyTask.class);
}
}
MyTask.java
public class MyTask extends DefaultTask {
private MyExtension extension;
@TaskAction
public void myTask() {
Project project = getProject();
extension = project.getExtensions().findByType(MyExtension.class);
PropertyManager propertyManager = new PropertyManager(project, extension);
propertyManager.setProperties();
System.out.println(extension.getValue());
}
MyExtension.java
public class MyExtension {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
build.gradle
apply plugin: 'maven'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'com.jfrog.bintray'
sourceCompatibility = 1.8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile gradleApi()
}
repositories {
mavenCentral()
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
}
}
task copyLibs(type: Copy) {
from configurations.runtime
into "$projectDir/libs"
}
MyTask.dependsOn(copyLibs) //not working
MyTask.dependsOn(compileJava) //not working
build.gradle
文件并在其中应用插件和配置任务? - Michael