I completed a custom task in groovy. If I provided a utility class for it, implemented in groovy (X.groovy) and placing it in buildsrc, the task will work. If I implement an equivalent class in Java (Y.java) and put it in the same directory, the task will end with the following error message:
:buildsrc:compileGroovystartup failed: General error during conversion: Could not load class 'com.myinc.gradle.api.data.Y' from file:/project/buildsrc/build/classes/main/com/myinc/gradle/api/data/Y.class.
The Y.class file exists at the location indicated in the error message. Build fails when Y.java is in any of the usual places:
buildsrc/src/main/groovy/.../Y.java<br> buildsrc/src/main/java/.../Y.java
The Gradle Documentation says: “You can just put the assembly source code in this directory and stick to the layout agreement for the Java / Groovy project,” and its default buildsrc construction script will be applied by default.
Source: http://www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:build_sources
The project layout allows groovy source directories to contain groovy and Java code.
Source: http://www.gradle.org/docs/current/userguide/groovy_plugin.html#sec:groovyCompile
Replicate:
Project / build.gradle:
task t (type: sample.MyTask) { println "configuring task" }
Project / buildsrc / SRC / Main / groovy / sample
MyTask.groovy
package sample import org.gradle.api.DefaultTask import org.gradle.api.tasks.TaskAction class MyTask extends DefaultTask { @TaskAction public void task() { println 'task action' new X().m()
X.groovy
package sample; class X { void m() { println "xm" } }
Y.java
package sample; public class Y { void m() { System.out.println("ym"); } }
OSX 10.8.4, IntelliJ 12.1, Gradle 1.8
source share