Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell Gradle to check two directories for main java source code

Tags:

java

gradle

I have a project full of tests that we use to query our environments. We run these tests using Gradle. I would like to run these tests from a standalone application to get rid of the Gradle dependency. I am using the gradle 'application' plugin and trying to run the JUnit tests using JUnitCore and everything is fine except I can't access my test classes from main.

I have

--main
--smokeTest
--longRunningTest

When I tell Gradle this it doesn't work.

sourceSets {
 main {
    java { srcDirs ['src/main/java', 'src/smokeTest/java'] }
    }
} 

It says "main" is not a recognized function. The java plugin is installed because I already have entries to define smokeTest and longRunningTest.

like image 566
techgnosis Avatar asked Apr 21 '15 21:04

techgnosis


People also ask

What is compileJava in gradle?

compileJava — JavaCompile. Depends on: All tasks which contribute to the compilation classpath, including jar tasks from projects that are on the classpath via project dependencies. Compiles production Java source files using the JDK compiler.

What is ProcessResources in gradle?

Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.

What is source compatibility in gradle?

According to Gradle documentation: sourceCompatibility is "Java version compatibility to use when compiling Java source." targetCompatibility is "Java version to generate classes for."

What is rootDir in gradle?

rootDir. The root directory of this project. The root directory is the project directory of the root project.


1 Answers

Not to steal the flame from @david-m-karr, just refining a bit:

sourceSets.main.java.srcDirs = ['src/main/java', 'src/smokeTest/java'] 

might work

like image 105
judoole Avatar answered Nov 14 '22 21:11

judoole