gpt4 book ai didi

java - 为什么 Gradle 试图为我的项目查找资源包?

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:07 26 4
gpt4 key购买 nike

我正在尝试找出多项目构建的问题。我已将问题简化为非常简单的设置。

<小时/>

等级信息

------------------------------------------------------------
Gradle 3.2.1
------------------------------------------------------------

Build time: 2016-11-22 15:19:54 UTC
Revision: 83b485b914fd4f335ad0e66af9d14aad458d2cc5

Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_40 (Oracle Corporation 24.0-b56)
OS: Linux 2.6.32-642.11.1.el6.i686 i386
<小时/>

目录结构

  • 根/
    • Hello World /
      • src/
        • com.dishbreak.teSTLab
          • HelloWorld.java
    • 设置.gradle
    • 构建.gradle

注意,我没有使用 Maven SDL,因为我尝试做的遗留项目没有使用。

<小时/>

HelloWorld.java

package com.dishbreak.testlab;

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello world!");

}

}
<小时/>

设置.gradle

include ":HelloWorld"

构建.gradle

subprojects {
apply plugin: "java"
sourceSets {
main {
java {
srcDirs = ['src/']
}
}
}
compileJava {
options.verbose = true
}
}
<小时/>

命令输出

[admin@box Plugins]$ gradle build
:HelloWorld:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':HelloWorld:compileJava'.
> Cannot find javac resource bundle for locale en_US

* 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: 0.87 secs

郑重声明,尝试使用 --info 标志会得到以下相关输出吗?

20:26:07.077 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':HelloWorld:compileJava' (up-to-date check took 0.002 secs) due to:
No history is available.
20:26:07.077 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':HelloWorld:compileJava'.
20:26:07.077 [INFO] [org.gradle.api.internal.changedetection.changes.RebuildIncrementalTaskInputs] All input files are considered out-of-date for incremental task ':HelloWorld:compileJava'.
20:26:07.077 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.7 -target 1.7 -d /redacted/root/HelloWorld/build/classes/main -verbose -g /redacted/root/HelloWorld/src/com/dishbreak/testlab/HelloWorld.java -XDuseUnsharedTable=true
20:26:07.078 [INFO] [org.gradle.api.internal.tasks.compile.JdkJavaCompiler] Compiling with JDK Java compiler API.
20:26:07.078 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
20:26:07.078 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':HelloWorld:compileJava'
20:26:07.079 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] :HelloWorld:compileJava FAILED

出于好奇,我尝试直接运行 javac 命令,它确实生成了一个可以运行的类文件!

[admin@box HelloWorld]$ javac -source 1.7 -target 1.7 -d /redacted/root/HelloWorld/build/classes/main -verbose -g /redacted/root/HelloWorld/src/com/dishbreak/testlab/HelloWorld.java -XDuseUnsharedTable=true
[parsing started RegularFileObject[/redacted/root/HelloWorld/src/com/dishbreak/testlab/HelloWorld.java]]
[parsing completed 14ms]
[search path for source files: .]
[search path for class files: /opt/java/jdk1.7.0_40/jre/lib/resources.jar,/opt/java/jdk1.7.0_40/jre/lib/rt.jar,/opt/java/jdk1.7.0_40/jre/lib/sunrsasign.jar,/opt/java/jdk1.7.0_40/jre/lib/jsse.jar,/opt/java/jdk1.7.0_40/jre/lib/jce.jar,/opt/java/jdk1.7.0_40/jre/lib/charsets.jar,/opt/java/jdk1.7.0_40/jre/lib/jfr.jar,/opt/java/jdk1.7.0_40/jre/classes,/opt/java/jdk1.7.0_40/jre/lib/ext/sunjce_provider.jar,/opt/java/jdk1.7.0_40/jre/lib/ext/sunpkcs11.jar,/opt/java/jdk1.7.0_40/jre/lib/ext/localedata.jar,/opt/java/jdk1.7.0_40/jre/lib/ext/zipfs.jar,/opt/java/jdk1.7.0_40/jre/lib/ext/sunec.jar,/opt/java/jdk1.7.0_40/jre/lib/ext/dnsns.jar,.]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/lang/String.class)]]
[checking com.dishbreak.testlab.HelloWorld]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/lang/AutoCloseable.class)]]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/lang/System.class)]]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/io/PrintStream.class)]]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/io/FilterOutputStream.class)]]
[loading ZipFileIndexFileObject[/opt/java/jdk1.7.0_40/lib/ct.sym(META-INF/sym/rt.jar/java/io/OutputStream.class)]]
[wrote RegularFileObject[/redacted/root/HelloWorld/build/classes/main/com/dishbreak/testlab/HelloWorld.class]]

当我尝试运行自动编译的类文件时?

[admin@box root]$ java -cp HelloWorld/build/classes/main/ com.dishbreak.testlab.HelloWorld
Hello world!
<小时/>

几个问题...

  • 为什么编译任务的详细输出在 Gradle 中没有给我任何信息?
  • 为什么 Gradle 要求提供资源包,而我的代码没有使用资源包?
  • 为什么当我直接输入javac命令时它会起作用?
  • 由于我没有使用 Maven SDL,还需要做什么吗?

最佳答案

您可以将其作为同级添加到 java 脚本 block

resources {
filter {
return it.exists()
}
}

关于java - 为什么 Gradle 试图为我的项目查找资源包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41820259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com