How can I reuse a helper class like project?

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:

  1. HelperClasses
  2. 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?

With no answer after 12 days I’ve moved the (essence of the) question to Stack Overflow

If a local Maven repo isn’t an option for you, then you can always just have the HelperClasses be their own Gradle project, build them to jars and then copy them into the Git repos for each project.

We use a local Maven repo, upload the jars for shared libraries, then declare them as dependencies in the build.gradle files for each individual project.

I’m not sure I get your second question however, it looks like you might have missed declaring classpath in your second project’s integrationTest task.

As to your other question about Jenkins,

You can certainly set up Jenkins to download the latest version of your HelperClasses, compile it, place it somewhere, then your other projects could use it.

Actually my problem is that EVERY solution is still an option. I’m new at my current job and looking for the best way to streamline code production. I have just about all the freedom in the world, I might even get a budget if I ask for it, but for now I’m trying to achieve it without extra costs.

I am starting to understand that using something like a local maven is probably the best way to go (I came across artifactory, maybe this is something we can use) and have asked a new question about how to best implement my helper project to build jars for that: Multi project jar generation