Hello, first post here, so sorry if I mess anything up! Ive been reading through the docs and been trying to get two java projects that I had previously, integrated into gradle.
So far I have a project A (main) which is depending on project B (subproject). Currently I am using a flat structure as so:
ProjectA
-->build.gradle
-->settings.gradle
-->src
-->code
ProjectB
-->build.gradle
-->settings.gradle
-->src
-->code
Funny thing is, is when I build a sample project from scratch using this system, this method is fine and I get an expected ProjectA jar with class files and a ProjectB jar. But when I try and implement this onto my java projects it doesnt seem to work. ProjectA jar is empty except for the manifest. (However, when I build ProjectB by itself, it does build a jar with the right class files)
Ive searched all over SO and here for something I might have missed when trying to implement gradle onto a java project (id post the links but thered be huge list), maybe theres something I missed about applying gradle to a java project already built? Ive posted the build/settings files for each below
ProjectA
–>build.gradle
apply plugin: 'java'
apply plugin: 'application'
sourceCompatibility = 1.8
repositories {
jcenter()
}
sourceSets {
main {
java {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
}
}
dependencies {
compile project(':ProjectB')
compile fileTree(dir: 'libraries', include: '*.jar')
// This dependency is found on compile classpath of this component and consumers.
compile 'com.google.guava:guava:20.0'
// Use JUnit test framework
testCompile 'junit:junit:4.12'
}
jar {
def manifestClasspath = configurations.runtime.collect { it.getName() }.join(' ')
manifest {
attributes 'Implementation-Title': "Bar thing",
'Implementation-Version': '0.0.1',
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion,
'Class-Path': manifestClasspath,
'Main-Class': 'gui.ProjectA'
}
}
–>settings.gradle
includeFlat "ProjectB"
rootProject.name = 'ProjectA'
ProjectB
–>build.gradle
apply plugin: 'java-library'
repositories {
jcenter()
}
sourceSets {
main {
java {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
}
}
dependencies {
compile fileTree(dir: 'libraries', include: '*.jar')
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
compile 'com.google.guava:guava:20.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
jar {
def manifestClasspath = configurations.runtime.collect { it.getName() }.join(' ')
manifest {
attributes 'Implementation-Title': "Foo thing",
'Implementation-Version': '0.0.1',
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion,
'Class-Path': manifestClasspath
}
}
–>settings.gradle
rootProject.name = 'ProjectB'