I want to test my Plugin hence I wrote that test class:
class MyPluginTest {
private def rootProject;
private def javaProject;
private def androidApp;
private def androidLibrary;
@Before
public void setUp() {
rootProject = ProjectBuilder.builder().withName('root').build();
javaProject = ProjectBuilder.builder().withName('java').withParent(rootProject).build();
javaProject.plugins.apply('java')
androidApp = ProjectBuilder.builder().withName('androidApp').withParent(rootProject).build();
androidApp.plugins.apply('com.android.application')
}
@Test
public void testShouldApplyPMDToJava() {
rootProject.plugins.apply(MyPlugin)
assertTrue(javaProject.plugins.hasPlugin(PmdPlugin))
assertTrue(androidApp.plugins.hasPlugin(PmdPlugin))
}
}
MyPlugin class looks like this:
class MyPlugin implements Plugin<Project> {
@Override
void apply(final Project project) {
project.subprojects { subProject ->
subProject.plugins.apply('pmd')
subProject.pmd {
toolVersion = '5.4.1'
}
}
}
}
When I execute my test class I get this stacktrace:
org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘com.android.application’]
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:160) at org.gradle.api.internal.plugins.DefaultPluginManager.addImperativePlugin(DefaultPluginManager.java:67) at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:55) at org.gradle.api.plugins.PluginContainer$apply.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at com.vanniktech.test.MyPluginTest.setUp(MyPluginTest.groovy:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: Basedir /tmp/gradle2959027909315402964projectDir/androidApp does not exist
at org.apache.tools.ant.Project.setBaseDir(Project.java:841)
at org.gradle.api.internal.project.DefaultAntBuilderFactory.create(DefaultAntBuilderFactory.java:38)
at org.gradle.api.internal.project.DefaultAntBuilderFactory.create(DefaultAntBuilderFactory.java:26)
at org.gradle.api.internal.project.AbstractProject.createAntBuilder(AbstractProject.java:488)
at org.gradle.api.internal.project.AbstractProject.getAnt(AbstractProject.java:482)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:4x`97)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaBeanProperty.getProperty(MetaBeanProperty.java:62)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.getProperties(BeanDynamicObject.java:221)
at org.gradle.api.internal.BeanDynamicObject.getProperties(BeanDynamicObject.java:116)
at org.gradle.api.internal.CompositeDynamicObject.getProperties(CompositeDynamicObject.java:130)
at org.gradle.api.internal.project.AbstractProject$4.create(AbstractProject.java:755)
at org.gradle.api.internal.project.AbstractProject$4.create(AbstractProject.java:753)
at org.gradle.util.SingleMessageLogger.whileDisabled(SingleMessageLogger.java:166)
at org.gradle.api.internal.project.AbstractProject.getProperties(AbstractProject.java:753)
at com.android.build.gradle.AndroidGradleOptions.getString(AndroidGradleOptions.java:142)
at com.android.build.gradle.AndroidGradleOptions.getBenchmarkName(AndroidGradleOptions.java:64)
at com.android.build.gradle.BasePlugin.apply(BasePlugin.java:298)
at com.android.build.gradle.AppPlugin.super$2$apply(AppPlugin.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
at com.android.build.gradle.AppPlugin.apply(AppPlugin.groovy:69)
at com.android.build.gradle.AppPlugin.apply(AppPlugin.groovy)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:44)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
… 33 more
Process finished with exit code 255
How can I work around this and actually test that my Plugin also does work with Android Gradle projects?
Those are my project dependencies:
dependencies {
compile gradleApi()
compile localGroovy()
compile 'com.android.tools.build:gradle:1.5.0'
}