我有以下文件夹结构,想要玩gradle测试。
在开始任何测试之前,我想看看哪些任务可用。
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that
depend on it.
buildNeeded - Assembles and tests this project and all projects it depends
on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root
project 'GradleTesting'.
components - Displays the components produced by root project
'GradleTesting'. [incubating]
dependencies - Displays all dependencies declared in root project
'GradleTesting'.
dependencyInsight - Displays the insight into a specific dependency in root
project 'GradleTesting'.
help - Displays a help message.
model - Displays the configuration model of root project 'GradleTesting'.
[incubating]
projects - Displays the sub-projects of root project 'GradleTesting'.
properties - Displays the properties of root project 'GradleTesting'.
tasks - Displays the tasks runnable from root project 'GradleTesting'.
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Other tasks
-----------
execute
所以我知道gradle没有任何问题。现在我在build.gradle文件中编写这段代码。
apply plugin: 'java'
task execute(type: JavaExec) {
//This line throws me an exception.
main = "src.main.java.Test"
classpath = sourceSets.main.runtimeClasspath
}
收到此消息。
$ gradle execute
:compileJava
:processResources UP-TO-DATE
:classes
:executeError: Could not find or load main class src.main.java.Test
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':execute'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe''
finished with non-zero exit value 1
任何想法如何解决此错误?
感谢。
答案 0 :(得分:2)
'src / main / java'是java文件的文件系统路径。 包名称从这里开始。
在您的情况下,没有包名称,完全限定的类名称为“Test”,因此,将build.gradle更改为:
apply plugin: 'java'
task execute(type: JavaExec) {
main = 'Test'
classpath = sourceSets.main.runtimeClasspath
}