I'm unable to add custom source set in my gradle project. How to initialize the version numbers in here? My gradle file looks like:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceSets {
demo
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
CodePudding user response:
You can set custom sourceSets like this in your build.gradle
main {
java {
srcDirs = ['src/gen/java', 'src/main/java']
}
}
The srcDirs is an array, so you can specify more than one source directory.
You can also specify custom source directories for your tests
test {
java {
srcDirs = ['src/integrated-test/java', 'src/test/java']
}
}
You can find some more info here https://www.baeldung.com/gradle-source-sets in section 3. They use the example for integrated tests, but the idea is the same.
Here is the official gradle document for source sets https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSet.html
CodePudding user response:
I found a solution. If your requirement is projectFolder/src/ -> Here you want to create a custom module other than the main and test. follow the below one. Its worked in Intellj ide.
sourceSets {
customModuleName.java.srcDir "src/customModuleName"
customModuleName.resources.srcDir "src/customModuleName"
}
// After adding the above block in build file. Go ahead and create a directory, it will show a module name in suggestion // Then inside module, Go to create a package. Here we can find java and resources folder in suggestion
