[英]Gradle not loading Java class files compiled from Java source placed in buildsrc
I've implemented a custom task in groovy. 我在groovy中实现了一个自定义任务。 If I provide a utility class for it implemented in groovy (X.groovy) and place it in buildsrc , the task works.
如果我为它在groovy(X.groovy)中实现它提供了一个实用程序类并将它放在buildsrc中 ,那么任务就可以了。 If I implement an equivalent class in Java (Y.java) and place it in the same directory, the task fails with the following error message:
如果我在Java(Y.java)中实现等效类并将其放在同一目录中,则任务失败并显示以下错误消息:
: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 specified in the error message. Y.class文件存在于错误消息中指定的位置。 The build fails when Y.java is in either of the usual places:
当Y.java位于任何常用位置时,构建失败:
buildsrc/src/main/groovy/.../Y.java<br>
buildsrc/src/main/java/.../Y.java
Gradle documentation says "you can just put your build source code in this directory and stick to the layout convention for a Java/Groovy project" and its default buildsrc build script will be applied. Gradle文档说“您可以将构建源代码放在此目录中并坚持Java / Groovy项目的布局约定”,并将应用其默认的buildsrc构建脚本。
Source: http://www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:build_sources 来源: http : //www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec : build_sources
Project Layout permits Groovy source directories to contain Groovy and Java code. Project Layout允许Groovy源目录包含Groovy和Java代码。
Source: http://www.gradle.org/docs/current/userguide/groovy_plugin.html#sec:groovyCompile 资料来源: http : //www.gradle.org/docs/current/userguide/groovy_plugin.html#sec : groovyCompile
To replicate: 复制:
project/build.gradle: 项目/的build.gradle:
task t (type: sample.MyTask) {
println "configuring task"
}
project/buildsrc/src/main/groovy/sample 项目/ buildsrc / src目录/主/常规/样本
MyTask.groovy 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()
// new Y().m() // uncommenting this line should generate an error when you build 't'
}
}
X.groovy X.groovy
package sample;
class X {
void m() {
println "x.m"
}
}
Y.java Y.java
package sample;
public class Y {
void m() {
System.out.println("y.m");
}
}
OSX 10.8.4, IntelliJ 12.1, Gradle 1.8 OSX 10.8.4,IntelliJ 12.1,Gradle 1.8
The problem in the larger context was an incompatibility in bytecode versions between the early access version of JDK8 and what the class loader in groovyCompile in Gradle 1.8 expects. 更大的上下文中的问题是JDK8的早期访问版本与Gradle 1.8中的groovyCompile中的类加载器所期望的字节码版本不兼容。 When I changed the language levels in IntelliJ back to JDK7, everything worked fine.
当我将IntelliJ中的语言级别更改回JDK7时,一切正常。
just an idea: Maybe it's related to the package declaration. 只是一个想法:也许它与包装声明有关。 Java is more picky here than groovy and expects the source file in an according directory.
Java比groovy更挑剔,并期望源文件在相应的目录中。 I couldn't reproduce your issue.
我无法重现你的问题。 Can you provide a small selfcontained project that demos your issue?
您能否提供一个小型的自包含项目来演示您的问题?
cheers, René 欢呼,勒内
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.