[#547] Configurable dependency locking

This implementation is somewhat special from our other Gradle properties, because it does not get declared in the root gradle.properties.  The reason is that included builds are supposed to have their own properties e.g.

root_project/gradle.properties
root_project/buildSrc/gradle.properties
root_project/build-conventions/gradle.properties

Instead of declaring the property in three different places which might lead to confusion, this leaves the property undeclared, with the Gradle scripts assuming a default value of true.  The only time this is expected to be overridden is due to a workaround for an Android Studio bug.
This commit is contained in:
Carter Jernigan 2022-07-22 13:00:04 -04:00 committed by GitHub
parent 72e50ec54a
commit 072d73e99c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 13 deletions

View File

@ -35,7 +35,7 @@ If you plan to fork the project to create a new app of your own, please make the
1. Configure secrets for [Continuous Integration](docs/CI.md).
# Known Issues
1. Intel-based machines may have trouble building in Android Studio. The workaround is to add the following line to `~/.gradle/gradle.properties` `ZCASH_IS_DEPENDENCY_LOCKING_ENABLED=false`. See [#420](https://github.com/zcash/secant-android-wallet/issues/420) for more information.
1. During builds, a warning will be printed that says "Unable to detect AGP versions for included builds. All projects in the build should use the same AGP version." This can be safely ignored. The version under build-conventions is the same as the version used elsewhere in the application.
1. When the code coverage Gradle property `IS_ANDROID_INSTRUMENTATION_TEST_COVERAGE_ENABLED` is enabled, the debug app APK cannot be run. The coverage flag should therefore only be set when running automated tests.
1. Test coverage for Compose code will be low, due to [known limitations](https://github.com/jacoco/jacoco/issues/1208) in the interaction between Compose and Jacoco.
@ -43,5 +43,3 @@ If you plan to fork the project to create a new app of your own, please make the
1. Android Studio will warn about the Gradle checksum. This is a [known issue](https://github.com/gradle/gradle/issues/9361) and can be safely ignored.
1. [#96](https://github.com/zcash/secant-android-wallet/issues/96) - Release builds print some R8 warnings which can be safely ignored.
1. During app first launch, the following exception starting with `AndroidKeysetManager: keyset not found, will generate a new one` is printed twice. This exception is not an error, and the code is not being invoked twice.
1. When running instrumentation tests for the app module, this warning will be printed `WARNING: Failed to retrieve additional test outputs from device.
com.android.ddmlib.SyncException: Remote object doesn't exist!` followed by a stacktrace. This can be safely ignored.

View File

@ -6,12 +6,35 @@ plugins {
buildscript {
dependencyLocking {
// This property is treated specially, as it is not defined by default in the root gradle.properties
// and declaring it in the root gradle.properties is ignored by included builds. This only picks up
// a value declared as a system property, a command line argument, or a an environment variable.
val isDependencyLockingEnabled = if (project.hasProperty("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED")) {
project.property("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED").toString().toBoolean()
} else {
true
}
if (isDependencyLockingEnabled) {
lockAllConfigurations()
}
}
}
dependencyLocking {
// This property is treated specially, as it is not defined by default in the root gradle.properties
// and declaring it in the root gradle.properties is ignored by included builds. This only picks up
// a value declared as a system property, a command line argument, or a an environment variable.
val isDependencyLockingEnabled = if (project.hasProperty("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED")) {
project.property("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED").toString().toBoolean()
} else {
true
}
if (isDependencyLockingEnabled) {
lockAllConfigurations()
}
}
// Per conversation in the KotlinLang Slack, Gradle uses Java 8 compatibility internally

View File

@ -3,7 +3,7 @@ dependencyResolutionManagement {
repositories {
val isRepoRestrictionEnabled = true
maven("https://dl.google.com/dl/android/maven2/") { //google()
google {
if (isRepoRestrictionEnabled) {
content {
includeGroup("androidx.navigation")
@ -15,7 +15,7 @@ dependencyResolutionManagement {
}
}
}
maven("https://repo.maven.apache.org/maven2/") { // mavenCentral()
mavenCentral {
if (isRepoRestrictionEnabled) {
content {
excludeGroup("androidx.navigation")

View File

@ -1,5 +1,13 @@
dependencyLocking {
val isDependencyLockingEnabled = if (project.hasProperty("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED")) {
project.property("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED").toString().toBoolean()
} else {
true
}
if (isDependencyLockingEnabled) {
lockAllConfigurations()
}
}
tasks {

View File

@ -1,8 +1,18 @@
buildscript {
dependencyLocking {
lockMode.set(LockMode.STRICT)
// This property is treated specially, as it is not defined by default in the root gradle.properties
// and declaring it in the root gradle.properties is ignored by included builds. This only picks up
// a value declared as a system property, a command line argument, or a an environment variable.
val isDependencyLockingEnabled = if (project.hasProperty("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED")) {
project.property("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED").toString().toBoolean()
} else {
true
}
if (isDependencyLockingEnabled) {
lockAllConfigurations()
}
}
}
plugins {

View File

@ -6,12 +6,35 @@ plugins {
buildscript {
dependencyLocking {
// This property is treated specially, as it is not defined by default in the root gradle.properties
// and declaring it in the root gradle.properties is ignored by included builds. This only picks up
// a value declared as a system property, a command line argument, or a an environment variable.
val isDependencyLockingEnabled = if (project.hasProperty("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED")) {
project.property("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED").toString().toBoolean()
} else {
true
}
if (isDependencyLockingEnabled) {
lockAllConfigurations()
}
}
}
dependencyLocking {
// This property is treated specially, as it is not defined by default in the root gradle.properties
// and declaring it in the root gradle.properties is ignored by included builds. This only picks up
// a value declared as a system property, a command line argument, or a an environment variable.
val isDependencyLockingEnabled = if (project.hasProperty("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED")) {
project.property("ZCASH_IS_DEPENDENCY_LOCKING_ENABLED").toString().toBoolean()
} else {
true
}
if (isDependencyLockingEnabled) {
lockAllConfigurations()
}
}
// Per conversation in the KotlinLang Slack, Gradle uses Java 8 compatibility internally

View File

@ -14,7 +14,7 @@ Start by making sure the command line with Gradle works first, because **all the
1. Install JVM 11 or greater on your system. Our setup has been tested with Java 11-17. Although a variety of JVM distributions are available and should work, we have settled on recommending [Adoptium/Temurin](https://adoptium.net), because this is the default distribution used by Gradle toolchains. For Windows or Linux, be sure that the `JAVA_HOME` environment variable points to the right Java version. Note: If you switch from a newer to an older JVM version, you may see an error like the following `> com.android.ide.common.signing.KeytoolException: Failed to read key AndroidDebugKey from store "~/.android/debug.keystore": Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available`. A solution is to delete the debug keystore and allow it to be re-generated.
1. Android Studio has an embedded JVM, although running Gradle tasks from the command line requires a separate JVM to be installed. Our Gradle scripts are configured to use toolchains to automatically install the correct JVM version.
1. Install Android Studio and the Android SDK
1. Download [Android Studio](https://developer.android.com/studio/). We typically use the stable version of Android Studio, unless specifically noted due to short-term known issues. For example, due to issue #420 Intel-based machines should avoid Android Studio Chipmunk and use Android Studio Dolphin instead.
1. Download [Android Studio](https://developer.android.com/studio/). We typically use the stable version of Android Studio, unless specifically noted due to short-term known issues. Note that due to issue #420 Intel-based machines may have trouble building in Android Studio. The workaround is to add the following line to `~/.gradle/gradle.properties` `ZCASH_IS_DEPENDENCY_LOCKING_ENABLED=false`.
1. During the Android Studio setup wizard, choose the "Standard" setup option
1. Note the file path where Android Studio will install the Android developer tools, as you will need this path later
1. Continue and let Android Studio download and install the rest of the Android developer tools