UPDATE
I think I fixed the output directories I was having where everything was going all over the place (I also upgraded to Gradle 4.7 and JUnit5). My only question, which isn’t a problem right now is that there were .xml and .html files being generated in a resources directory which are no longer getting generated. What I did:
I added a couple of variables:
def rootDirAbsPath = rootProject.projectDir.absolutePath
def rootBuildDirAbsPath = rootDirAbsPath + '/build/'
Then in my project(’:webapp’) and project(’:webapp_test) I have:
buildDir = file(rootBuildDirAbsPath + 'net.firezeal.bubbleshadow/' + project.name + '/build')
My sourceSets for webapp:
sourceSets {
main {
output.resourcesDir = file(rootBuildDirAbsPath + 'net.firezeal.bubbleshadow/' + project.name + '/resources')
java {
outputDir = file(rootBuildDirAbsPath + 'net.firezeal.bubbleshadow/' + project.name + '/build')
srcDir 'src/main/java/net/firezeal/bubbleshadow/' + project.name
}
}
}
My sourceSets for webapp_test:
sourceSets {
test {
output.resourcesDir = file(rootBuildDirAbsPath + 'net.firezeal.bubbleshadow/' + project.name + '/resources')
java {
outputDir = file(rootBuildDirAbsPath + 'net.firezeal.bubbleshadow/' + project.name + '/build')
srcDir 'src/main/java/net.firezeal.bubbleshadow/' + project.name
}
}
}
previous post:
Hello,
I am new to Gradle. I built a test-case to deal with some issues I was having with separating test code and production code into different packages. I solved that problem but I want to make sure I’m organizing my project in a sensible way (I’ll be putting it into Eclipse later, if that matters).
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── mainapp
│ └── src
│ └── main
│ └── java
│ └── net.firezeal.bubbleshadow
│ └── build
│ └── mainapp
│ ├── libs
│ │ └── mainapp.jar
│ └── tmp
│ ├── compileJava
│ └── jar
│ └── MANIFEST.MF
├── mainapp_test
│ └── src
│ └── main
│ └── java
│ └── net.firezeal.bubbleshadow
│ └── build
│ └── mainapp_test
│ ├── reports
│ │ └── tests
│ │ └── test
│ │ ├── classes
│ │ │ └── net.firezeal.test.bubbleshadow.AppTest.html
│ │ ├── css
│ │ │ ├── base-style.css
│ │ │ └── style.css
│ │ ├── index.html
│ │ ├── js
│ │ │ └── report.js
│ │ └── packages
│ │ └── net.firezeal.test.bubbleshadow.html
│ ├── test-results
│ │ └── test
│ │ ├── TEST-net.firezeal.test.bubbleshadow.AppTest.xml
│ │ └── binary
│ │ ├── output.bin
│ │ ├── output.bin.idx
│ │ └── results.bin
│ └── tmp
│ └── compileTestJava
├── settings.gradle
└── src
└── main
└── java
├── build.gradle
├── net.firezeal.bubbleshadow
│ ├── build
│ │ ├── mainapp
│ │ │ └── net
│ │ │ └── firezeal
│ │ │ └── bubbleshadow
│ │ │ └── App.class
│ │ └── mainapp_test
│ │ └── net
│ │ └── firezeal
│ │ └── test
│ │ └── bubbleshadow
│ │ └── AppTest.class
│ ├── mainapp
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── net
│ │ └── firezeal
│ │ └── bubbleshadow
│ │ └── mainapp
│ │ └── App.java
│ ├── mainapp_test
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── net
│ │ └── firezeal
│ │ └── test
│ │ └── bubbleshadow
│ │ └── mainapp_test
│ │ └── AppTest.java
│ └── module-info.java
└── settings.gradle
63 directories, 25 files
What I would like:
All build files to go under ‘./src/main/java/net.firezeal.bubbleshadow/build/—name of project—/…’
Currently my .class files are going into that directory but mainapp and mainapp_test are still generating files into the root directory of the project.
Also, I need to know what variables to modify in order to get the organization structure the way I want. Just modifying buildDir didn’t seem to be sufficient.
But, if anyone has any suggestions on proper organization structure I’d be glad to hear that as well.
Here is my build.gradle file under ./src/main/java (the ./build.gradle file is empty)
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.6/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
}
ext.moduleName = 'net.firezeal.bubbleshadow'
// Define the main class for the application
mainClassName = '$moduleName'
subprojects {
afterEvaluate {
repositories {
jcenter()
}
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
// '--module', mainClassName
]
classpath = files()
}
}
compileTestJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
// '--module', mainClassName,
'--add-modules', 'junit',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
]
classpath = files()
}
}
test {
inputs.property("moduleName", moduleName)
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
// '--module', mainClassName,
'--add-modules', 'ALL-MODULE-PATH',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath,
]
classpath = files()
}
}
}
}
project(':mainapp') {
apply plugin: 'java'
buildDir = file('./src/main/java/net.firezeal.bubbleshadow/build/' + project.name)
repositories {
jcenter()
}
dependencies {
// This dependency is found on compile classpath of this component and consumers.
compile 'com.google.guava:guava:23.0'
testCompile "junit:junit:4.12"
}
task mainapp_test(dependsOn: ':mainapp_test:test') {
}
group 'net.firezeal.bubbleshadow'
sourceSets {
main {
output.resourcesDir = file('../src/main/java/net.firezeal.bubbleshadow/build/' + project.name)
java {
outputDir = file('../src/main/java/net.firezeal.bubbleshadow/build/' + project.name)
srcDir '../src/main/java/net.firezeal.bubbleshadow/mainapp'
}
}
}
}
project(':mainapp_test') {
apply plugin: 'java'
buildDir = file('./src/main/java/net.firezeal.bubbleshadow/build/' + project.name)
repositories {
jcenter()
}
dependencies {
// This dependency is found on compile classpath of this component and consumers.
compile 'com.google.guava:guava:23.0'
testCompile "junit:junit:4.12"
}
group 'net.firezeal.bubbleshadow'
dependencies {
compile project(':mainapp')
}
sourceSets {
test {
output.resourcesDir = file('../src/main/java/net.firezeal.bubbleshadow/build/' + project.name)
java {
outputDir = file('../src/main/java/net.firezeal.bubbleshadow/build/'+ project.name)
srcDir '../src/main/java/net.firezeal.bubbleshadow/mainapp_test'
}
}
}
}