如何将资源目录而不是单个文件包含到编译类路径中?

时间:2015-05-03 09:34:06

标签: java netbeans gradle netbeans-plugins

我正在尝试使用gradle(版本2.3)而不是ant来编译this project

有两个子模块; cachedb编译没有问题;至于另一个,NBStudioCore,我使用antlr插件等完全运用了正确的依赖...它编译,但注释处理器阻碍了。

完整分支:https://github.com/fge/NBStudio/tree/topic/gradle

与原版的区别:

  • 将src重命名为src / main / java;
  • 所有非java文件到src / main / resources。

子模块NBStudioCore的build.gradle读取:

apply(plugin: "antlr");

repositories {
    mavenCentral();
    maven {
        url "http://bits.netbeans.org/maven2";
    }
}

dependencies {
    antlr(group: "org.antlr", name: "antlr4", version: "4.5");

    compile project(":cachedb");

    compile(group: "org.netbeans.api", name: "org-openide-util",
        version: "RELEASE80");
    compile(group: "org.netbeans.api", name: "org-netbeans-api-search",
        version: "RELEASE80");
    compile(group: "org.netbeans.api", name: "org-netbeans-modules-lexer",
        version: "RELEASE80");
    compile(group: "org.netbeans.api", name: "org-netbeans-modules-parsing-api",
        version: "RELEASE80");
    compile(group: "org.netbeans.api", name: "org-netbeans-modules-editor",
        version: "RELEASE80");
    compile(group: "org.netbeans.api",
        name: "org-netbeans-modules-editor-completion", version: "RELEASE80");
    compile(group: "org.netbeans.api",
        name: "org-netbeans-spi-editor-hints", version: "RELEASE80");
    compile(group: "org.netbeans.api", name: "org-netbeans-core-multiview",
        version: "RELEASE80");
    compile(group: "org.netbeans.api", name: "org-netbeans-modules-csl-api",
        version: "RELEASE80");
}

compileJava任务输出(在目录NBStudioCore内使用../gradlew compileJava运行)是这样的:

:NBStudioCore:clean
:NBStudioCore:generateGrammarSource
:cachedb:compileJava UP-TO-DATE
:cachedb:processResources UP-TO-DATE
:cachedb:classes UP-TO-DATE
:cachedb:jar UP-TO-DATE
:NBStudioCore:compileJava
[...]
/home/fge/work/src/NBStudio/NBStudioCore/src/main/java/org/nbstudio/core/cls/clsVisualElement.java:19: error: Cannot find resource org/nbstudio/core/cls/class.png
@MultiViewElement.Registration(
^
[...]
/home/fge/work/src/NBStudio/NBStudioCore/src/main/java/org/nbstudio/core/OpenFileAction.java:30: error: Cannot find resource org/nbstudio/Bundle.properties
public class OpenFileAction implements ActionListener {
       ^
[...]
/home/fge/work/src/NBStudio/NBStudioCore/src/main/java/org/nbstudio/core/bas/package-info.java:5: error: Cannot find resource org/nbstudio/core/bas/bas.gif
@TemplateRegistration(folder = "Cache", content = "basTemplate.bas", displayName = "BAS Routine")
^
[...]
/home/fge/work/src/NBStudio/NBStudioCore/src/main/java/org/nbstudio/core/cls/newFileWizard.java:23: error: Cannot find resource org/nbstudio/core/cls/clsTemplate.cls
@TemplateRegistration(folder = "Cache", content = "clsTemplate.cls", displayName = "Cache Class")
^
[...]
warning: layer file Editors/text/isc-cls/MultiView/org-nbstudio-core-cls-clsVisualElement.instance was never written
warning: layer file Actions/System/org-netbeans-modules-openfile-OpenFileAction.instance was never written
warning: layer file Loaders/text/isc-bas/Factories/org-nbstudio-core-bas-basDataObject.instance was never written
warning: layer file Templates/Cache/clsTemplate.cls was never written
4 errors
36 warnings
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':NBStudioCore:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.121 secs

如果我使用--debug启动,我会看到编译类路径不包含资源目录。但在这里我需要它。

我尝试将此行添加到build.gradle:

dependencies {
    // ....
    compile fileTree("src/main/resources");

但它将每个单独的文件添加到编译类路径中,这不是我想要的...我只想要目录。

我试图超过半天没有成功实现这一目标!我该怎么做?

0 个答案:

没有答案