I’m trying to create a setup where I can have an abstractish helperclasses project (with functions like, send email, connect to database type bla parse xml file etc). And i’m trying to introduce gradle into the mix.
I would like to have 2 (and later, more) git repositories with my projects:
- HelperClasses
- ProjectThatUsesHelperClasses
(3. AnotherProjectThatUsesHelperClasses)
I obviously don’t want multiple copies of the helperclasses as subprojects but I would like to use all the lovely gradle functions
Currently I have been testing plugins like findbugs, Pmd etc. and they work fine on HelperClasses
build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
compile 'org.apache.poi:poi-ooxml:3.9'
compile 'javax.mail:mail:1.4.1'
compile fileTree(dir: 'libs', include: ['sqljdbc4.jar'])
integrationTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
jar {
manifest {
attributes 'Implementation-Title': 'Helper Classes',
'Implementation-Version': version
}
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integTest/java')
}
resources.srcDir file('src/integTest/resources')
}
}
task integrationTest(type: Test){
description = 'Run the integration tests.'
group = 'verification'
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
apply from: System.getenv('GRADLE_SCRIPTS_HOME')+"check.gradle"
apply from: System.getenv('GRADLE_SCRIPTS_HOME')+"jacoco.gradle"
check.gradle:
apply plugin: 'findbugs'
apply plugin: 'jdepend'
apply plugin: 'pmd'
repositories {
mavenCentral()
}
findbugsMain {
reports {
xml.enabled false
html.enabled true
html.destination "${buildDir}/reports/findbugs/main.html"
}
omitVisitors = ['UnreadFields']
ignoreFailures = true
}
findbugsTest {
reports {
xml.enabled false
html.enabled true
html.destination "${buildDir}/reports/findbugs/test.html"
}
ignoreFailures = true
}
findbugsIntegrationTest {
reports {
xml.enabled false
html.enabled true
html.destination "${buildDir}/reports/findbugs/integrationTest.html"
}
ignoreFailures = true
}
jdepend{
ignoreFailures = true
}
pmd {
ignoreFailures = true
}
tasks.withType(Pmd){
reports{
xml.enabled=false
html.enabled=true
}
}
jacoco.gradle:
apply plugin: 'jacoco'
repositories {
mavenCentral()
}
jacoco {
toolVersion = "0.7.1.201405082137"
reportsDir = file("$buildDir/customJacocoReportDir")
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/reports/jacoco/"
}
}
task jacocoIntegrationTestReport(type: JacocoReport){
sourceSets sourceSets.main
executionData test, integrationTest
}
but when I try to run tests on my second project the project just runs the HelperClasses test and integrationTest functions. However if I execute gradle build it will build both classes.
second project build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = "com.something.ApplicationMainClass"
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
compile project(':HelperClasses')
compile 'org.apache.poi:poi-ooxml:3.9'
compile 'javax.mail:mail:1.4.1'
testCompile 'junit:junit:4.12'
integrationTestCompile 'junit:junit:4.12'
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integTest/java')
}
resources.srcDir file('src/integTest/resources')
}
}
jar {
manifest {
attributes 'Implementation-Title': 'report generator', 'Implementation-Version': version,
'Main-Class' : mainClassName, 'Class-Path': configurations.runtime.files.collect {"$it.name"}.join(' ')
}
}
task integrationTest(type: Test){
description = 'Run the integration tests.'
group = 'verification'
testClassesDir = sourceSets.integrationTest.output.classesDir
}
apply from: System.getenv('GRADLE_SCRIPTS_HOME')+"check.gradle"
apply from: System.getenv('GRADLE_SCRIPTS_HOME')+"jacoco.gradle"
I presume that I should not be reusing names of tests or something, or define them in another way, but I’m not sure if my projects setup is the right way to start. What would you guys advise me to do?