diff --git a/.travis.yml b/.travis.yml index 2d7be14b..75e04281 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ cache: - ${HOME}/.m2 script: -- make test +- ./gradlew preMerge after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile deleted file mode 100644 index 40517b9a..00000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -.PHONY: install-hooks regenerate-samples test run-hooks - -.git/hooks/pre-commit: venv - ${CURDIR}/venv/bin/pre-commit install --install-hooks - -install-hooks: .git/hooks/pre-commit - @true - -run-hooks: venv - ${CURDIR}/venv/bin/pre-commit run --all-files - -test: run-hooks - ${CURDIR}/gradlew --project-dir gradle-plugin build check - ${CURDIR}/gradlew generateSwagger - # The check task requires a lot of MetaSpace - ${CURDIR}/gradlew assembleDebug check -Dorg.gradle.jvmargs="-Xmx4g -XX:MaxMetaspaceSize=2g" - -venv: - virtualenv venv - ./venv/bin/pip install pre-commit diff --git a/build.gradle.kts b/build.gradle.kts index 3a22244e..b485eb35 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,3 +5,67 @@ subprojects { jcenter() } } + +val installVenv = tasks.register("installVenv", Exec::class.java) { + description = "Install a new virtualenv in ./venv" + + outputs.dir("./venv") + + commandLine("virtualenv", "venv") +} + +val installPreCommit = tasks.register("installPreCommit", Exec::class.java) { + description = "Installs pre-commit in ./venv" + + dependsOn(installVenv) + + outputs.file("./venv/bin/pre-commit") + + commandLine("./venv/bin/pip", "install", "pre-commit") +} + +val installHooks = tasks.register("installHooks", Exec::class.java) { + description = "Run pre-commit hooks without installing them" + + dependsOn(installPreCommit) + + outputs.file(".git/hooks/pre-commit") + inputs.file(".pre-commit-config.yaml") + + commandLine("./venv/bin/pre-commit", "install", "--install-hooks") +} + +val runHooks = tasks.register("runHooks", Exec::class.java) { + description = "Run pre-commit hooks" + + dependsOn(installPreCommit) + + commandLine("./venv/bin/pre-commit", "run", "--all-files") +} + +val preMerge = tasks.register("preMerge") { + description = "Runs pre-commit hooks, build the plugin and sample and execute tests." + + dependsOn(runHooks) + dependsOn(gradle.includedBuild("gradle-plugin").task(":plugin:build")) + dependsOn(gradle.includedBuild("gradle-plugin").task(":plugin:check")) + dependsOn(subprojects.filter { it.name != "samples" }.map { it.tasks.named("check") }) +} + +plugins { + id("com.android.library").version("3.5.3").apply(false) + id("com.yelp.codegen.plugin").version("1.3.0").apply(false) + id("io.gitlab.arturbosch.detekt").version("1.4.0").apply(false) + kotlin("android").version("1.3.61").apply(false) +} + +subprojects { + afterEvaluate { // Remove when we have lazy configuration + tasks.all { + if (this is org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { + // we need the generated files before we run the kotlin compile task + dependsOn(tasks.named("generateSwagger")) + } + } + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..17332baf --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +# The check task requires a lot of MetaSpace. Not sure if it is a leak or something else +# But it is needed to make the tasks pass +org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=2g diff --git a/samples/groovy-android/build.gradle b/samples/groovy-android/build.gradle index fd0bf4d9..601855a6 100644 --- a/samples/groovy-android/build.gradle +++ b/samples/groovy-android/build.gradle @@ -1,22 +1,9 @@ -buildscript { - repositories { - gradlePluginPortal() - google() - mavenCentral() - jcenter() - } - - dependencies { - classpath "com.android.tools.build:gradle:3.5.3" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" - classpath "com.yelp.codegen:plugin:1.3.0" - } +plugins { + id("com.android.library") + id("kotlin-android") + id("com.yelp.codegen.plugin") } -apply plugin: "com.android.library" -apply plugin: "kotlin-android" -apply plugin: "com.yelp.codegen.plugin" - android { compileSdkVersion = 28 defaultConfig { diff --git a/samples/junit-tests/build.gradle b/samples/junit-tests/build.gradle index 8f60e869..5c2dbff9 100644 --- a/samples/junit-tests/build.gradle +++ b/samples/junit-tests/build.gradle @@ -1,25 +1,11 @@ -buildscript { - repositories { - gradlePluginPortal() - google() - mavenCentral() - jcenter() - } - - dependencies { - classpath "com.android.tools.build:gradle:3.5.3" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" - classpath "com.yelp.codegen:plugin:1.3.0" - classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.4.0" - } +plugins { + id("com.android.library") + id("kotlin-android") + id("com.yelp.codegen.plugin") + id("io.gitlab.arturbosch.detekt") + id("kotlin-kapt") } -apply plugin: "com.android.library" -apply plugin: "kotlin-android" -apply plugin: "com.yelp.codegen.plugin" -apply plugin: "io.gitlab.arturbosch.detekt" -apply plugin: "kotlin-kapt" - android { compileSdkVersion = 28 defaultConfig { diff --git a/samples/kotlin-android-moshi-codegen/build.gradle.kts b/samples/kotlin-android-moshi-codegen/build.gradle.kts index c7a6e6f1..25e2bef9 100644 --- a/samples/kotlin-android-moshi-codegen/build.gradle.kts +++ b/samples/kotlin-android-moshi-codegen/build.gradle.kts @@ -1,8 +1,8 @@ plugins { - id("com.android.library") version "3.5.3" - kotlin("android") version "1.3.61" - id("com.yelp.codegen.plugin") version "1.3.0" - kotlin("kapt") version "1.3.61" + id("com.android.library") + id("kotlin-android") + id("com.yelp.codegen.plugin") + id("kotlin-kapt") } android { diff --git a/samples/kotlin-android/build.gradle.kts b/samples/kotlin-android/build.gradle.kts index f810f740..e0790dc3 100644 --- a/samples/kotlin-android/build.gradle.kts +++ b/samples/kotlin-android/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id("com.android.library") version "3.5.3" - kotlin("android") version "1.3.61" - id("com.yelp.codegen.plugin") version "1.3.0" + id("com.android.library") + kotlin("android") + id("com.yelp.codegen.plugin") } android { diff --git a/samples/kotlin-coroutines/build.gradle b/samples/kotlin-coroutines/build.gradle index ad9c498c..dffe25ad 100644 --- a/samples/kotlin-coroutines/build.gradle +++ b/samples/kotlin-coroutines/build.gradle @@ -1,22 +1,9 @@ -buildscript { - repositories { - gradlePluginPortal() - google() - mavenCentral() - jcenter() - } - - dependencies { - classpath "com.android.tools.build:gradle:3.5.3" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" - classpath "com.yelp.codegen:plugin:1.3.0" - } +plugins { + id("com.android.library") + id("kotlin-android") + id("com.yelp.codegen.plugin") } -apply plugin: "com.android.library" -apply plugin: "kotlin-android" -apply plugin: "com.yelp.codegen.plugin" - android { compileSdkVersion = 28 defaultConfig { diff --git a/settings.gradle.kts b/settings.gradle.kts index 33254d9d..2557900c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,6 +7,7 @@ pluginManagement { jcenter() google() } + resolutionStrategy { eachPlugin { if ("com.android" in requested.id.id) {