Skip to content

Commit 5c9ae86

Browse files
author
Marcel Schnelle
authored
Separate Android & Java modules (#152)
I’m giving up trying to mix them both in a single project. Instead, two subfolders become the root for the individual modules; open “plugin” with IntelliJ IDEA, and “instrumentation” with Android Studio.
1 parent 733a561 commit 5c9ae86

File tree

82 files changed

+701
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+701
-171
lines changed

.circleci/config.yml

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defaults: &defaults
77
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError"'
88

99
cache_key: &cache_key
10-
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "android-junit5/build.gradle.kts" }}-{{ checksum "android-junit5-tests/build.gradle.kts" }}-{{ checksum "instrumentation/build.gradle.kts" }}-{{ checksum "instrumentation-runner/build.gradle.kts" }}-{{ checksum "sample/build.gradle.kts" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
10+
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "plugin/android-junit5-tests/build.gradle.kts" }}-{{ checksum "instrumentation/api/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
1111

1212
version: 2
1313
jobs:
@@ -17,23 +17,24 @@ jobs:
1717
- checkout
1818
- restore_cache:
1919
<<: *cache_key
20-
- run:
21-
name: Download Dependencies
22-
command: ./gradlew androidDependencies --no-daemon
2320

2421
- run:
25-
name: Build Plugin
26-
command: ./gradlew :android-junit5:assemble --stacktrace --no-daemon
22+
name: (Plugin) Build
23+
command: cd plugin && ./gradlew :android-junit5:assemble --stacktrace --no-daemon
2724
- run:
28-
name: Test Plugin
29-
command: ./gradlew :android-junit5-tests:check --stacktrace --no-daemon
30-
25+
name: (Plugin) Test
26+
command: cd plugin && ./gradlew :android-junit5-tests:check --stacktrace --no-daemon
27+
28+
- run:
29+
name: (Instrumentation) Download Dependencies
30+
command: cd instrumentation && ./gradlew androidDependencies --no-daemon
3131
- run:
32-
name: Build Instrumentation
33-
command: ./gradlew :instrumentation:assemble :instrumentation-runner:assemble --stacktrace --no-daemon
32+
name: (Instrumentation) Build
33+
command: cd instrumentation && ./gradlew :api:assemble :runner:assemble --stacktrace --no-daemon
3434
- run:
35-
name: Test Instrumentation
36-
command: ./gradlew :instrumentation:check :instrumentation-runner:check --stacktrace --no-daemon
35+
name: (Instrumentation) Test
36+
command: cd instrumentation && ./gradlew :api:check :runner:check --stacktrace --no-daemon
37+
3738
- save_cache:
3839
<<: *cache_key
3940
paths:
@@ -44,13 +45,13 @@ jobs:
4445
paths:
4546
- project
4647
- store_artifacts:
47-
path: android-junit5-tests/build/reports/tests/test
48+
path: plugin/android-junit5-tests/build/reports/tests/test
4849
destination: plugin
4950
- store_artifacts:
50-
path: instrumentation/build/reports
51-
destination: instrumentation
51+
path: instrumentation/api/build/reports
52+
destination: instrumentation-api
5253
- store_artifacts:
53-
path: instrumentation-runner/build/reports
54+
path: instrumentation/runner/build/reports
5455
destination: instrumentation-runner
5556

5657
deploy_snapshots:
@@ -61,8 +62,11 @@ jobs:
6162
- restore_cache:
6263
<<: *cache_key
6364
- run:
64-
name: Deploy SNAPSHOTs
65-
command: ./gradlew publishLibraryPublicationToSnapshotRepository --stacktrace --no-daemon
65+
name: (Plugin) Deploy SNAPSHOTs
66+
command: cd plugin && ./gradlew publishLibraryPublicationToSnapshotRepository --stacktrace --no-daemon
67+
- run:
68+
name: (Instrumentation) Deploy SNAPSHOTs
69+
command: cd instrumentation && ./gradlew publishLibraryPublicationToSnapshotRepository --stacktrace --no-daemon
6670

6771
deploy_plugin_release:
6872
<<: *defaults
@@ -72,8 +76,8 @@ jobs:
7276
- restore_cache:
7377
<<: *cache_key
7478
- run:
75-
name: Deploy plugin
76-
command: ./gradlew generatePomFileForLibraryPublication publish :android-junit5:bintrayUpload --stacktrace --no-daemon
79+
name: (Plugin) Deploy
80+
command: cd plugin && ./gradlew generatePomFileForLibraryPublication publish :android-junit5:bintrayUpload --stacktrace --no-daemon
7781

7882
# deploy_instrumentation_release:
7983
# <<: *defaults
@@ -83,8 +87,8 @@ jobs:
8387
# - restore_cache:
8488
# <<: *cache_key
8589
# - run:
86-
# name: Deploy instrumentation
87-
# command: ./gradlew generatePomFileForLibraryPublication publish :instrumentation:bintrayUpload :instrumentation-runner:bintrayUpload --stacktrace --no-daemon
90+
# name: (Instrumentation) Deploy
91+
# command: cd instrumentation && ./gradlew generatePomFileForLibraryPublication publish :api:bintrayUpload :runner:bintrayUpload --stacktrace --no-daemon
8892

8993
workflows:
9094
version: 2

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
*.iml
22
.gradle
33
local.properties
4-
.idea/*
5-
!.idea/runConfigurations
6-
!.idea/codeStyleSettings.xml
4+
*/.idea/*
5+
!*/.idea/runConfigurations
6+
!*/.idea/codeStyleSettings.xml
77
.DS_Store
88
build/
99
out/

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ Currently, Google hasn't shared any immediate plans to bring first-party support
192192
- [Add support for JUnit 5 (issuetracker.google.com)](https://issuetracker.google.com/issues/127100532)
193193
- [JUnit 5 support (github.com/android/android-test)](https://github.com/android/android-test/issues/224)
194194

195+
# Building Locally
196+
197+
This repository contains multiple modules, divided into two sub-projects. The repository's root directory contains build logic shared across the sub-projects, which in turn use symlinks to connect to the common build scripts in their parent folder.
198+
199+
- `instrumentation`: The root folder for Android-based modules, namely the instrumentation libraries & a sample application. After cloning, open this project in Android Studio.
200+
- `plugin`: The root folder for Java-based modules, namely the Gradle plugin for JUnit 5 on Android, as well as its test module. After cloning, open this project in IntelliJ IDEA.
201+
195202
## License
196203

197204
```
@@ -216,7 +223,7 @@ See also the [full License text](LICENSE).
216223
[junit5ug]: https://junit.org/junit5/docs/current/user-guide
217224
[circleci]: https://circleci.com/gh/mannodermaus/android-junit5
218225
[sonatyperepo]: https://oss.sonatype.org/content/repositories/snapshots
219-
[sampletests]: sample/src/test
226+
[sampletests]: instrumentation/sample
220227
[wiki-dsl]: https://github.com/mannodermaus/android-junit5/wiki/Configuration-DSL
221228
[wiki-migration]: https://github.com/mannodermaus/android-junit5/wiki/Migrating-from-1.0.x
222229
[wiki-gettingstarted]: https://github.com/mannodermaus/android-junit5/wiki/Getting-Started

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Versions {
1313

1414
const val aapt2: String = "3.2.1-4818971"
1515

16-
const val com_android_tools_build_gradle: String = "3.2.1"
16+
const val com_android_tools_build_gradle: String = "3.4.0-rc02"
1717

1818
const val lint_gradle: String = "26.2.1"
1919

@@ -45,7 +45,7 @@ object Versions {
4545

4646
const val assertj_core: String = "3.11.1"
4747

48-
const val org_jetbrains_kotlin: String = "1.3.11"
48+
const val org_jetbrains_kotlin: String = "1.3.21"
4949

5050
const val org_jetbrains_spek: String = "1.2.1"
5151

gradle/wrapper/gradle-wrapper.jar

-982 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

.idea/runConfigurations/Sample__Run_Unit_Tests__Gradle_.xml renamed to instrumentation/.idea/runConfigurations/Sample__Run_Unit_Tests__Gradle_.xml

File renamed without changes.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2+
import org.gradle.api.tasks.testing.logging.TestLogEvent
3+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
4+
5+
plugins {
6+
id("com.android.library")
7+
kotlin("android")
8+
}
9+
10+
android {
11+
compileSdkVersion(Android.compileSdkVersion)
12+
13+
dexOptions {
14+
javaMaxHeapSize = Android.javaMaxHeapSize
15+
}
16+
17+
defaultConfig {
18+
minSdkVersion(Android.instrumentationMinSdkVersion)
19+
targetSdkVersion(Android.targetSdkVersion)
20+
versionCode = 1
21+
versionName = "1.0"
22+
multiDexEnabled = true
23+
24+
// Usually, this is automatically applied through the Gradle Plugin
25+
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
26+
testInstrumentationRunnerArgument("runnerBuilder",
27+
"de.mannodermaus.junit5.AndroidJUnit5Builder")
28+
}
29+
30+
sourceSets {
31+
getByName("main").java.srcDir("src/main/kotlin")
32+
getByName("test").java.srcDir("src/test/kotlin")
33+
getByName("androidTest").java.srcDir("src/androidTest/kotlin")
34+
}
35+
36+
compileOptions {
37+
setSourceCompatibility(JavaVersion.VERSION_1_8)
38+
setTargetCompatibility(JavaVersion.VERSION_1_8)
39+
}
40+
41+
lintOptions {
42+
// JUnit 4 refers to java.lang.management APIs, which are absent on Android.
43+
warning("InvalidPackage")
44+
}
45+
46+
packagingOptions {
47+
exclude("META-INF/LICENSE.md")
48+
exclude("META-INF/LICENSE-notice.md")
49+
}
50+
51+
testOptions {
52+
unitTests.apply {
53+
isReturnDefaultValues = true
54+
}
55+
}
56+
}
57+
58+
tasks.withType<KotlinCompile> {
59+
kotlinOptions.jvmTarget = "1.8"
60+
}
61+
62+
tasks.withType<Test> {
63+
failFast = true
64+
testLogging {
65+
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
66+
exceptionFormat = TestExceptionFormat.FULL
67+
}
68+
}
69+
70+
val commonTestImplementation = configurations.create("commonTestImplementation")
71+
configurations {
72+
getByName("androidTestImplementation").extendsFrom(commonTestImplementation)
73+
getByName("testImplementation").extendsFrom(commonTestImplementation)
74+
}
75+
76+
dependencies {
77+
implementation(Libs.kotlin_stdlib)
78+
implementation(Libs.com_android_support_test_runner)
79+
implementation(Libs.junit_jupiter_api)
80+
81+
// This is required by the "instrumentation-runner" companion library,
82+
// since it can't provide any JUnit 5 runtime libraries itself
83+
// due to fear of prematurely incrementing the minSdkVersion requirement.
84+
runtimeOnly(Libs.junit_platform_runner)
85+
86+
commonTestImplementation(Libs.assertj_core)
87+
commonTestImplementation(Libs.mockito_core)
88+
commonTestImplementation(Libs.junit_jupiter_api)
89+
commonTestImplementation(Libs.junit_jupiter_engine)
90+
91+
androidTestImplementation(Libs.assertj_android)
92+
androidTestImplementation(Libs.espresso_core)
93+
94+
androidTestRuntimeOnly(project(":runner"))
95+
96+
// Obviously, these dependencies should be mostly "runtimeOnly",
97+
// but we have to override bundled APIs from the IDE as much as possible for Android Studio.
98+
testImplementation(Libs.junit_platform_engine)
99+
testImplementation(Libs.junit_platform_launcher)
100+
testImplementation(Libs.junit_jupiter_api)
101+
testImplementation(Libs.junit_jupiter_engine)
102+
testImplementation(Libs.junit_vintage_engine)
103+
}
104+
105+
// ------------------------------------------------------------------------------------------------
106+
// Deployment Setup
107+
//
108+
// Releases are pushed to jcenter via Bintray, while snapshots are pushed to Sonatype OSS.
109+
// This section defines the necessary tasks to push new releases and snapshots using Gradle tasks.
110+
// ------------------------------------------------------------------------------------------------
111+
112+
val deployConfig by extra<Deployed> { Artifacts.Instrumentation.Library }
113+
apply(from = "$rootDir/gradle/deployment.gradle")
File renamed without changes.

instrumentation/src/androidTest/kotlin/de/mannodermaus/junit5/test/ActivityTestIntegrationTests.kt renamed to instrumentation/api/src/androidTest/kotlin/de/mannodermaus/junit5/test/ActivityTestIntegrationTests.kt

File renamed without changes.

0 commit comments

Comments
 (0)