I want to have a project with 3 submodules as follows:
proj:spring
proj:plainjava
proj:android
proj:android:app
Where plainjava is a jar that is installed in the local repository. spring + android:app are dependant on it.
Currently if I try running gradle from the root directory or import it to the ide's, it results in various errors.
Execution failed for task ':android:app:compileDebugJavaWithJavac'.
Running separate task for android builds fine.
As I have figured out I need the following tasks to execute for the whole build in the following order:
- proj:plainjava:publishMavenJavaPublicationToMavenLocal
- proj:spring:bootRepackage
- ??? Task To build android succesfully, currently builds in android studio explicitly.
For the development purposes I also need to execute each task on it's own. Running
proj:spring:bootRepackage
Somehow triggers dependency resolution for the android, app and plainjava
actual files:
proj settings.gradle
include 'commonobjects', 'server', 'android', 'android:app'
proj build.gradle, has specific custom tasks that allow ci to build artifacts.
task myCleanLibraries {}
myCleanLibraries.dependsOn ':commonobjects:clean'
task myPublishLibraries {}
myPublishLibraries.dependsOn ':commonobjects:publishToMavenLocal'
task myCleanRest {}
myCleanRest.dependsOn ':server:clean', ':android:app:clean'
task myBuildRest {}
myBuildRest.dependsOn ':server:build', ':android:app:assembleDebug'
task myLibraries {}
myLibraries.dependsOn 'myCleanLibraries', 'myPublishLibraries'
myPublishLibraries.mustRunAfter 'myCleanLibraries'
task myRest {}
myRest.dependsOn 'myCleanRest', 'myBuildRest'
myBuildRest.mustRunAfter 'myCleanRest'
task myAll {}
myAll.dependsOn 'myLibraries', 'myRest'
myRest.mustRunAfter 'myLibraries'
proj:spring build.gradle
group 'com.example'
version '0.0.VERSIONNUMBER'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
defaultTasks 'clean', 'build'
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
jar {
baseName = 'server'
version = '0.0.9999'
}
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-logging'
compile 'org.projectlombok:lombok'
compile 'io.jsonwebtoken:jjwt:0.7.0'
compile 'mysql:mysql-connector-java:6.0.5'
compile 'com.example:commonobjects:0.0.9999'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
proj:commonobjects settings.gradle
rootProject.name = 'commonobjects'
proj:commonobjects build.gradle
group 'com.example'
version '0.0.9999'
apply plugin: 'java'
apply plugin: 'maven-publish'
jar {
baseName = 'commonobjects'
version = '0.0.9999'
}
repositories {
mavenCentral()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testCompile 'junit:junit:4.11'
}
proj:android settings.gradle
include ':app'
proj:android build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
}
}
proj:android:app build.gradle
def ANDROID_SUPPORT_DEPENDENCY_VERSION = '25.1.0'
def DAGGER_DEPENDENCY_VERSION = '2.10'
def OK_HTTP_DEPENDENCY_VERSION = '3.7.0'
def RETROFIT_DEPENDENCY_VERSION = '2.1.0'
def RETROFIT_JACKSON_DEPENDENCY_VERSION = '2.1.0'
def BUTTER_KNIFE_DEPENDENCY_VERSION = '8.5.1'
def JAVAX_ANNOTATION_JSR250_API_DEPENDENCY_VERSION = '1.0'
def GREEN_ROBOT_EVENT_BUS_DEPENDENCY_VERSION = '3.0.0'
def RX_JAVA_DEPENDENCY_VERSION = '2.0.5'
def RX_ANDROID_JAVA_DEPENDENCY_VERSION = '2.0.1'
defaultTasks 'clean', 'assembleDebug'
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
classpath "com.android.tools.build:gradle:2.3.1"
}
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
apply plugin: "com.android.application"
apply plugin: "idea"
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "myandroidappid"
minSdkVersion 14
targetSdkVersion 25
versionCode 9999
versionName "0.0.9999"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
// debug {
// buildConfigField "String", "PARSE_APPLICATION_ID", "\"1\""
// buildConfigField "String", "PARSE_API_KEY", "\"1\""
// }
release {
minifyEnabled true
proguardFiles "android-proguard-android.txt", "proguard-rules.txt"
// buildConfigField "String", "PARSE_APPLICATION_ID", "\"1\""
// buildConfigField "String", "PARSE_API_KEY", "\"1\""
}
}
packagingOptions {
pickFirst 'META-INF/LICENSE'
}
}
dependencies {
// Add jars supplied
compile fileTree(dir: 'libs', include: ['*.jar'])
// Test related
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.1'
androidTestCompile "com.android.support:support-annotations:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
androidTestCompile "com.android.support.test:runner:0.5"
// MYOSCA dependencies
compile('com.example:commonobjects:0.0.9999')
// Android support libraries
compile "com.android.support:appcompat-v7:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
compile "com.android.support:design:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
compile "com.android.support:support-annotations:${ANDROID_SUPPORT_DEPENDENCY_VERSION}"
// An HTTP & HTTP/2 client for Android and Java applications
compile "com.squareup.okhttp3:okhttp:${OK_HTTP_DEPENDENCY_VERSION}"
// Retrofit: A type-safe HTTP client for Android and Java
compile "com.squareup.retrofit2:retrofit:${RETROFIT_DEPENDENCY_VERSION}"
compile "com.squareup.retrofit2:converter-jackson:${RETROFIT_JACKSON_DEPENDENCY_VERSION}"
// Butterknife: Field and method binding for Android views
compile "com.jakewharton:butterknife:${BUTTER_KNIFE_DEPENDENCY_VERSION}"
annotationProcessor "com.jakewharton:butterknife-compiler:${BUTTER_KNIFE_DEPENDENCY_VERSION}"
// Dagger DI
compile "com.google.dagger:dagger:${DAGGER_DEPENDENCY_VERSION}"
annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_DEPENDENCY_VERSION}"
compile "com.google.dagger:dagger-android:${DAGGER_DEPENDENCY_VERSION}"
annotationProcessor "com.google.dagger:dagger-android-processor:${DAGGER_DEPENDENCY_VERSION}"
compile "com.google.dagger:dagger-android-support:${DAGGER_DEPENDENCY_VERSION}"
compile "com.google.dagger:dagger:${DAGGER_DEPENDENCY_VERSION}"
annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_DEPENDENCY_VERSION}"
provided "javax.annotation:jsr250-api:${JAVAX_ANNOTATION_JSR250_API_DEPENDENCY_VERSION}"
// Event bus
compile "org.greenrobot:eventbus:${GREEN_ROBOT_EVENT_BUS_DEPENDENCY_VERSION}"
// RxJava a library for composing asynchronous and event-based programs by using observable sequences.
compile "io.reactivex.rxjava2:rxjava:${RX_JAVA_DEPENDENCY_VERSION}"
compile "io.reactivex.rxjava2:rxandroid:${RX_ANDROID_JAVA_DEPENDENCY_VERSION}"
// Google Guava for preconditions
compile 'com.google.guava:guava:20.0'
}