<NME> build.gradle
<BEF> /*
 * Just run this script using "gradlew", and it will show you typical examples of how to use it.
 */
defaultTasks 'cgeoHelp'

tasks.register('cgeoHelp') {
    group = 'cgeo'
    description = 'Displays help for building cgeo.'
    doLast {
        println ''
        println 'These are some of the available commands for building cgeo.'
        println ''
        println 'cleaning all generated artifacts:'
        println '    gradlew clean'
        println ''
        println 'build:'
        println '    gradlew assembleDebug'
        println ''
        println 'install on connected device/emulator:'
        println '    gradlew installBasicDebug'
        println ''
        println 'run app on connected device/emulator:'
        println '    gradlew runBasicDebug'
        println ''
        println 'instrumentation tests on connected device/emulator:'
        println '    gradlew connectedBasicDebugAndroidTest'
        println ''
        println 'pure unit tests WITHOUT device'
        println '    gradlew testBasicDebugUnitTest'
        println ''
        println 'all unit tests (pure and instrumentation)'
        println '    gradlew testDebug'
        println ''
        println 'check project dependencies for updates:'
        println '    gradlew dependencies main:dependencies'
        println ''
        println 'check gradle dependencies for updates:'
        println '    gradlew dependencyUpdates'
        println ''
        println 'Use "gradlew tasks" for more available tasks.'
        println ''
        println ''
        println 'Available build types are: debug, nightly (requires an env var named NB), ' +
                'rc (requires an env var named RC), release.'
    }
    }
}

/*
 * Build scan plugin shall be applied first
 */
apply plugin: 'com.gradle.build-scan'
/*
 * update check for all components in this gradle script
 */
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'idea'

buildscript {
    repositories {
        jcenter()
        // gradle build-scan for profiling our build script
        maven {
            url 'https://plugins.gradle.org/m2'
        }
        google()
    }
    dependencies {
        // these dependencies are used by gradle plugins, not by our projects

        // check for updates of gradle plugin dependencies
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.27.0'

        // Android gradle plugin
        classpath 'com.android.tools.build:gradle:3.4.2'

        // un-mocking of portable Android classes
        classpath 'de.mobilej.unmock:UnMockPlugin:0.7.3'

        // monitor our application method limit
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.6'

        // ribbonizer for easier distinction of non-release builds
        classpath 'com.github.gfx.ribbonizer:ribbonizer-plugin:2.1.0'

        // gradle build script profiling
        classpath 'com.gradle:build-scan-plugin:2.4.2'
    }
}

// filter out non release version updates and other updates we cannot use
allprojects {
    configurations {
            resolutionStrategy {
                componentSelection {
                    all { ComponentSelection selection ->
                        if (['alpha', 'beta', 'rc', 'cr', 'm', 'pr'].any { qualifier -> selection.candidate.version.contains(qualifier)}) {
                            selection.reject('Release candidate')
                        }

                        // see https://assertj.github.io/doc/#assertj-core-android
                        // AssertJ Core 3.x is compatible with Android API Level 26+, except for soft assertions and assumptions.
                        // AssertJ Core 2.x is Android compatible with Android API Level 26+ and API Level < 26 except for Path assertions.
                        if (selection.candidate.group == 'org.assertj' && selection.candidate.module == 'assertj-core' && selection.candidate.version.substring(0,1).toInteger() > 2) {
                            selection.reject("assertj 3.x or higher requires Java 7 SE classes not available in Android")
                        }

                        // Apache Commons IO 2.6 fails in FileUtils.deleteDirectory()
                        // (uses java.nio.file.Path - which is first contained in Android API26)
                        if (selection.candidate.group == 'commons-io' && selection.candidate.module == 'commons-io' && selection.candidate.version.substring(0,1).toInteger()*10+selection.candidate.version.substring(2,3).toInteger() > 25) {
                            selection.reject("Apache Commons IO 2.6 calls methods not available in the Android runtime untli API26.")
                        }
                    }
                }
                // new versions of checkstyle use guava 27, which has troublesome dependencies: https://groups.google.com/forum/#!topic/guava-announce/Km82fZG68Sw
                force 'com.google.guava:guava:26.0-jre'

                // force this version because of conflict to our resolutionStrategy from lint-gradle
                // TODO check necessity after every gradle update (gradlew :main:lintBasicDebug)
                force 'com.android.tools.build:aapt2-proto:4.2.2-7147631'
            }
        }
    }
}

/*
 * common configuration for the Java projects
 */
subprojects {
    repositories {
        mavenCentral()
        // Android Support libraries are now in an online Maven repository
        google()
        // integrate as last one - for versions by commit ID
        maven {
            url 'https://jitpack.io'
        }
    }

    // disable warning of annotation processor about annotation types with no registered processor (like @NonNull)
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:-processing"
    }

    idea.module {
        downloadJavadoc = true
        downloadSources = true
    }
}

/*
 * Make sure that we use the source distribution when updating the wrapper from the command line.
 */
tasks.named('wrapper') {
    distributionType = Wrapper.DistributionType.ALL
}

/*
 * Configuration for dependencyUpdates, see https://github.com/ben-manes/gradle-versions-plugin
 */
tasks.named('dependencyUpdates') {
    checkForGradleUpdate = true
    revision = "release"
    gradleReleaseChannel = "current"
    outputFormatter = "plain, html"
}

<MSG> update the gradle build-scan plugin

- use version 3.0, for gradle 5.x
- change to plugins{} syntax, also for the other plugins
- change order in build.gradle
  because of:
	"only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
	See https://docs.gradle.org/5.6.2/userguide/plugins.html#sec:plugins_block for information on the plugins {} block"

<DFF> @@ -1,3 +1,41 @@
+// first of all the buildscript block, then the plugins block
+buildscript {
+    repositories {
+        jcenter()
+        // gradle build-scan for profiling our build script
+        maven {
+            url 'https://plugins.gradle.org/m2'
+        }
+        google()
+    }
+    dependencies {
+        // these dependencies are used by gradle plugins, not by our projects
+
+        // Android gradle plugin
+        classpath 'com.android.tools.build:gradle:3.4.2'
+
+        // un-mocking of portable Android classes
+        classpath 'de.mobilej.unmock:UnMockPlugin:0.7.3'
+
+        // monitor our application method limit
+        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.6'
+
+        // ribbonizer for easier distinction of non-release builds
+        classpath 'com.github.gfx.ribbonizer:ribbonizer-plugin:2.1.0'
+    }
+}
+
+plugins {
+    // IDEA tasks for the project, see https://docs.gradle.org/current/userguide/idea_plugin.html
+    id 'idea'
+
+    // check for updates of gradle plugin dependencies
+    id 'com.github.ben-manes.versions' version '0.27.0'
+
+    // Build scan plugin, see https://plugins.gradle.org/plugin/com.gradle.build-scan
+    id 'com.gradle.build-scan' version '3.0'
+}
+
 /*
  * Just run this script using "gradlew", and it will show you typical examples of how to use it.
  */
@@ -46,48 +84,6 @@ tasks.register('cgeoHelp') {
     }
 }
 
-/*
- * Build scan plugin shall be applied first
- */
-apply plugin: 'com.gradle.build-scan'
-/*
- * update check for all components in this gradle script
- */
-apply plugin: 'com.github.ben-manes.versions'
-apply plugin: 'idea'
-
-buildscript {
-    repositories {
-        jcenter()
-        // gradle build-scan for profiling our build script
-        maven {
-            url 'https://plugins.gradle.org/m2'
-        }
-        google()
-    }
-    dependencies {
-        // these dependencies are used by gradle plugins, not by our projects
-
-        // check for updates of gradle plugin dependencies
-        classpath 'com.github.ben-manes:gradle-versions-plugin:0.27.0'
-
-        // Android gradle plugin
-        classpath 'com.android.tools.build:gradle:3.4.2'
-
-        // un-mocking of portable Android classes
-        classpath 'de.mobilej.unmock:UnMockPlugin:0.7.3'
-
-        // monitor our application method limit
-        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.6'
-
-        // ribbonizer for easier distinction of non-release builds
-        classpath 'com.github.gfx.ribbonizer:ribbonizer-plugin:2.1.0'
-
-        // gradle build script profiling
-        classpath 'com.gradle:build-scan-plugin:2.4.2'
-    }
-}
-
 // filter out non release version updates and other updates we cannot use
 allprojects {
     configurations {

update the gradle build-scan plugin