Last active
December 28, 2015 19:09
-
-
Save corsc/7548415 to your computer and use it in GitHub Desktop.
Companion Files to Blog post http://wp.me/p3GNDA-3Q
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Project properties | |
project.group = 'org.sage42.sample' | |
project.version = '1.0.0' | |
// standard android plugin | |
apply plugin: 'android' | |
// plugin with signing (aka deploying) APKs | |
apply plugin: 'signing' | |
// Extra config required by Android Annotations | |
configurations | |
{ | |
apt | |
} | |
dependencies | |
{ | |
// include the lib project | |
compile project(':lib') | |
// Extra config required by Android Annotations | |
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}" | |
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}" | |
// dependancies for testing (Robotium, Mockito, etc) | |
instrumentTestCompile "com.jayway.android.robotium:robotium-solo:$robotiumVersion" | |
instrumentTestCompile "com.google.dexmaker:dexmaker:$dexmakerVersion" | |
instrumentTestCompile "com.google.dexmaker:dexmaker-mockito:$dexmakerMockitoVersion" | |
instrumentTestCompile "org.mockito:mockito-core:$mockitoVersion" | |
} | |
// Config for the android plugin | |
android | |
{ | |
// build tools and compile values (see parent build.gradle file) | |
buildToolsVersion "$androidBuildToolsVersion" | |
compileSdkVersion androidCompileSdkVersion | |
defaultConfig | |
{ | |
// target values (see parent build.gradle file) | |
minSdkVersion androidMinSdkVersion | |
targetSdkVersion androidTargetSdkVersion | |
// test package name | |
// NOTE: must match the package in the test directory and must be different from the app package | |
testPackageName "org.sage42.sample.app.test" | |
// standard android test runner | |
testInstrumentationRunner "android.test.InstrumentationTestRunner" | |
} | |
sourceSets | |
{ | |
// define the file locations for the app | |
main | |
{ | |
manifest.srcFile 'AndroidManifest.xml' | |
java.srcDirs = ['src/main/java'] | |
resources.srcDirs = ['src/main/resources'] | |
aidl.srcDirs = ['src/main/aidl'] | |
renderscript.srcDirs = ['src/main/rs'] | |
res.srcDirs = ['res'] | |
assets.srcDirs = ['assets'] | |
} | |
// define the file locations for the android test code | |
instrumentTest | |
{ | |
manifest.srcFile '../test/AndroidManifest.xml' | |
java.srcDirs = ['../test/src/test/java'] | |
resources.srcDirs = ['../test/src/test/resources'] | |
res.srcDirs = ['res'] | |
assets.srcDirs = ['assets'] | |
} | |
} | |
} | |
// AA processing | |
android.applicationVariants.all | |
{ | |
variant -> | |
aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}") | |
println "****************************" | |
println "variant: ${variant.name}" | |
println "manifest: ${variant.processResources.manifestFile}" | |
println "aptOutput: ${aptOutput}" | |
println "****************************" | |
variant.javaCompile.doFirst | |
{ | |
println "*** compile doFirst ${variant.name}" | |
aptOutput.mkdirs() | |
variant.javaCompile.options.compilerArgs += [ | |
'-processorpath', configurations.apt.getAsPath(), | |
'-AandroidManifestFile=' + variant.processResources.manifestFile, | |
'-s', aptOutput | |
] | |
} | |
} | |
// To use: gradle sonarRunner | |
sonarRunner | |
{ | |
sonarProperties | |
{ | |
property 'sonar.projectName', 'driver-app' | |
properties['sonar.sources'] = android.sourceSets.main.java.srcDirs | |
properties['sonar.tests'] = android.sourceSets.instrumentTest.java.srcDirs | |
properties['sonar.binaries'] = file('build/classes/debug') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ Base Directory for the entire project. | |
/build.gradle Top-level build file containing Gradle config for all of the sub-modules. | |
/settings.gradle Standard gradle settings.gradle file that maps to the app and lib "sub-modules" | |
/app/ Android App Project | |
/app/AndroidManifest.xml (Almost standard, only change is to move the code from src to src/main/java/) | |
/app/build.gradle | |
/app/src/main/java/ | |
/app/res/ | |
/lib/ Java Project | |
/lib/build.gradle (Used for any non Android code, things like JSON parsing and business logic) | |
/lib/src/main/java/ (Keeping it separate will allow us to unit test much faster with jUnit instead of android tools) | |
/lib/src/main/resources/ | |
/lib/src/test/java/ Tests for the java code in /src/main/java | |
/lib/src/test/resources/ | |
/test/ Android Test Project | |
/test/src/test/java/ (Almost standard, only change is to move the code from src to src/test/java/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// standard java plugin | |
apply plugin: 'java' | |
dependencies | |
{ | |
// dependancies for testing (junit, hamcrest, etc) | |
testCompile group: 'junit', name: 'junit', version: '4.+' | |
} | |
// java settings | |
sourceCompatibility = 1.6 | |
targetCompatibility = 1.6 | |
// define the file locations | |
sourceSets | |
{ | |
main | |
{ | |
java.srcDirs = ['src/main/java'] | |
resources.srcDirs = ['src/main/resources'] | |
} | |
test | |
{ | |
java.srcDirs = ['src/test/java'] | |
resources.srcDirs = ['src/test/resources'] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can | |
// add configuration options common | |
// to all sub-projects/modules. | |
buildscript { | |
repositories { | |
// maven central and local maven repo | |
mavenLocal() | |
mavenCentral() | |
} | |
dependencies { | |
// gradle android tools | |
classpath 'com.android.tools.build:gradle:0.5.+' | |
// Gradle Android Unit Testing Plugin (not yet used) | |
// Working Progress https://github.com/JakeWharton/gradle-android-test-plugin | |
classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.+' | |
} | |
} | |
// These are the common version numbers, etc for the rest of the gradle files | |
configure(allprojects) { | |
ext.androidVersion = '4.1.1.4' | |
ext.androidSDKVersion = '18' | |
ext.androidBuildToolsVersion = '18.1.1' | |
ext.androidSupportVersion = '18.0.1' | |
ext.androidCompileSdkVersion = 19 | |
ext.androidMinSdkVersion = 8 | |
ext.androidTargetSdkVersion = 19 | |
ext.androidAnnotationsVersion = '2.7.1' | |
ext.robotiumVersion = '4.3' | |
ext.dexmakerVersion = '1.0' | |
ext.dexmakerMockitoVersion = '1.0' | |
ext.mockitoVersion = '1.9.5' | |
} | |
// inject these settings in all of the sub projects | |
configure(subprojects) { subproject -> | |
repositories { | |
mavenCentral() | |
mavenLocal() | |
} | |
} | |
// Base Config for a local sonar installation | |
// To use: gradle sonarRunner | |
apply plugin: 'sonar-runner' | |
sonarRunner | |
{ | |
sonarProperties | |
{ | |
// Project Name | |
// This can be anything, whatever describes your project | |
property 'sonar.projectName', 'Sage 42 - Sample App Project' | |
// Project Key | |
// this should be unique, so the namespace of the app is a good option | |
property 'sonar.projectKey', 'org.sage42.sample' | |
// Comma separated list of sub projects | |
// This will often match the values in the settings.gradle | |
property 'sonar.modules', 'app,lib' | |
// Mapping list for modules to their actual directories | |
property 'app.sonar.projectBaseDir', './app/' | |
property 'lib.sonar.projectBaseDir', './lib/' | |
// Project Version | |
property 'sonar.projectVersion', '1.0' | |
// java version | |
property 'sonar.java.target', '1.6' | |
// sonar connection parameters | |
property 'sonar.host.url', 'http://localhost:9000' | |
property 'sonar.jdbc.url', 'jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true' | |
property 'sonar.jdbc.driverClassName', 'com.mysql.jdbc.Driver' | |
property 'sonar.jdbc.username', 'sonar' | |
property 'sonar.jdbc.password', 'sonar' | |
// so far incomplete attempts to get code coverage to work | |
property 'sonar.dynamicAnalysis', 'reuseReports' | |
property 'sonar.surefire.reportsPath', 'build/instrumentTest-results/connected/' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment