Skip to content

Commit 512085d

Browse files
committed
Update Gradle configuration: enhance test logging, align Kotlin dependencies, and upgrade testing libraries to latest versions.
1 parent 92b1fdb commit 512085d

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

contentstack/build.gradle

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ android {
4444
includeAndroidResources = true
4545
returnDefaultValues = true
4646
all {
47+
testLogging {
48+
events 'passed', 'skipped', 'failed'
49+
}
4750
jacoco {
4851
includeNoLocationClasses = true
4952
excludes = ['jdk.internal.*']
@@ -126,61 +129,57 @@ dependencies {
126129
def junit = "4.13.2"
127130
def mockito = "5.2.0"
128131
def mockitoKotlin = "2.2.0"
132+
def okhttp = "5.3.2"
133+
def retrofit = "2.11.0"
129134
configurations.configureEach { resolutionStrategy.force 'com.android.support:support-annotations:23.1.0' }
135+
// androidx.test pulls an older kotlin-stdlib; align for Snyk SNYK-JAVA-ORGJETBRAINSKOTLIN-2393744 (fixed in Kotlin 2.1.0+).
136+
configurations.configureEach {
137+
resolutionStrategy.eachDependency { details ->
138+
if (details.requested.group == 'org.jetbrains.kotlin' &&
139+
(details.requested.name == 'kotlin-stdlib' ||
140+
details.requested.name == 'kotlin-stdlib-common' ||
141+
details.requested.name == 'kotlin-stdlib-jdk7' ||
142+
details.requested.name == 'kotlin-stdlib-jdk8')) {
143+
details.useVersion '2.1.21'
144+
}
145+
}
146+
}
130147
implementation fileTree(include: ['*.jar'], dir: 'libs')
131148
implementation "com.android.volley:volley:$volley"
132-
implementation "junit:junit:$junit"
133149

134150
// For AGP 7.4+
135151
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
136152

137153
// Unit Testing Dependencies
138-
testImplementation 'junit:junit:4.13.2'
154+
testImplementation "junit:junit:$junit"
139155
testImplementation "org.mockito:mockito-core:$mockito"
140156
testImplementation "org.mockito:mockito-inline:$mockito"
141157
testImplementation 'org.mockito:mockito-android:5.2.0'
142158
testImplementation 'org.robolectric:robolectric:4.15' // Updated to fix security vulnerabilities
143-
testImplementation 'androidx.test:core:1.5.0'
144-
testImplementation 'androidx.test:runner:1.5.2'
145-
testImplementation 'androidx.test.ext:junit:1.1.5'
146-
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
159+
testImplementation 'androidx.test:core:1.6.1'
160+
testImplementation 'androidx.test:runner:1.6.1'
161+
testImplementation 'androidx.test.ext:junit:1.2.1'
162+
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp"
147163
testImplementation 'org.json:json:20231013'
148164
// PowerMock for advanced mocking
149165
testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
150166
testImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
151167
testImplementation 'org.powermock:powermock-core:2.0.9'
152168

153169
// Android Test Dependencies
154-
androidTestImplementation 'androidx.test:core:1.5.0'
155-
androidTestImplementation 'androidx.test:runner:1.5.2'
156-
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
157-
androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1', {
170+
androidTestImplementation 'androidx.test:core:1.6.1'
171+
androidTestImplementation 'androidx.test:runner:1.6.1'
172+
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
173+
androidTestImplementation('androidx.test.espresso:espresso-core:3.6.1', {
158174
exclude group: 'com.android.support', module: 'support-annotations'
159175
})
160176

161177
// implementation 'com.squareup.okio:okio:3.9.0'
162178
implementation 'com.github.rjeschke:txtmark:0.12'
163-
// // Retrofit
164-
implementation("com.squareup.retrofit2:retrofit:2.9.0")
165-
implementation 'com.squareup.retrofit2:converter-gson'
166-
// // OkHttp
167-
implementation 'com.squareup.okhttp3:okhttp'
179+
implementation "com.squareup.retrofit2:retrofit:$retrofit"
180+
implementation "com.squareup.retrofit2:converter-gson:$retrofit"
181+
implementation "com.squareup.okhttp3:okhttp:$okhttp"
168182
// implementation 'com.squareup.okhttp3:logging-interceptor:4.9.3'
169-
170-
constraints {
171-
implementation('com.squareup.retrofit2:converter-gson:2.9.0') {
172-
because 'gson 2.8.5 used by retrofit has a vulnerability'
173-
}
174-
implementation('com.google.code.gson:gson@2.8.9') {
175-
because 'gson 2.8.5 used by retrofit has a vulnerability'
176-
}
177-
implementation('com.squareup.okhttp3:okhttp:4.9.3') {
178-
because 'kotlin stdlib 1.4.10 used by okhttp has a vulnerability'
179-
}
180-
implementation('org.jetbrains.kotlin:kotlin-stdlib@1.6.0') {
181-
because 'kotlin stdlib 1.4.10 used by okhttp has a vulnerability'
182-
}
183-
}
184183
}
185184
tasks.register('clearJar', Delete) { delete 'build/libs/contentstack.jar' }
186185
tasks.register('unzip', Copy) {
@@ -397,7 +396,18 @@ tasks.register('jacocoTestCoverageVerification', JacocoCoverageVerification) {
397396
]))
398397
}
399398

400-
// Make check task depend on coverage verification
401-
tasks.named('check') {
402-
dependsOn('jacocoTestReport', 'jacocoTestCoverageVerification')
399+
// Do not run JVM unit tests during `build`, `check`, etc. Enable only when you ask for them explicitly.
400+
// Examples: ./gradlew :contentstack:testDebugUnitTest | :contentstack:test | :contentstack:jacocoTestReport
401+
def requestedTaskBasenames = gradle.startParameter.taskNames.collect { it.split(':').last().toLowerCase() }
402+
def runJvmUnitTests = requestedTaskBasenames.any { t ->
403+
t == 'test' ||
404+
t ==~ /test.*unittest/ ||
405+
t in ['jacocotestreport', 'jacocotestcoveragewerification', 'jacococombinedreport']
406+
}
407+
gradle.projectsEvaluated {
408+
if (!runJvmUnitTests) {
409+
tasks.matching { it.name.matches('test.*UnitTest') }.configureEach { ut ->
410+
ut.enabled = false
411+
}
412+
}
403413
}

0 commit comments

Comments
 (0)