Skip to content

Commit

Permalink
Add and apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed Dec 18, 2021
1 parent 933b2f6 commit 0298fcf
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package co.anitrend.support.query.builder.annotation

/**
Expand All @@ -6,4 +22,4 @@ package co.anitrend.support.query.builder.annotation
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class EntitySchema
annotation class EntitySchema
15 changes: 13 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ repositories {
maven {
url = URI("https://www.jitpack.io")
}
maven {
setUrl("https://plugins.gradle.org/m2/")
}
}

val kotlinVersion = "1.5.31"
val buildToolsVersion = "7.0.3"
val manesVersion = "0.33.0"
val buildToolsVersion = "7.0.4"
val dokkaVersion = "1.5.31"
val manesVersion = "0.38.0"
val spotlessVersion = "5.12.1"

dependencies {
/** Depend on the android gradle plugin, since we want to access it in our plugin */
Expand All @@ -25,9 +30,15 @@ dependencies {
/** Depend on the kotlin plugin, since we want to access it in our plugin */
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")

/* Depend on the dokka plugin, since we want to access it in our plugin */
implementation("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion")

/** Dependency management */
implementation("com.github.ben-manes:gradle-versions-plugin:$manesVersion")

/** Spotless */
implementation("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion")

/* Depend on the default Gradle API's since we want to build a custom plugin */
implementation(gradleApi())
implementation(localGroovy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Libraries {
object Android {

object Tools {
private const val version = "7.0.3"
private const val version = "7.0.4"
const val buildGradle = "com.android.tools.build:gradle:$version"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ object Versions {
* **RR**_X.Y.Z_
* > **RR** reserved for build flavours and **X.Y.Z** follow the [versionName] convention
*/
const val versionCode = major.times(10_000) +
minor.times(1000) +
const val versionCode = major.times(1_000_000) +
minor.times(10_000) +
patch.times(100) +
candidate.times(10)
candidate

/**
* Naming schema: X.Y.Z-variant##
Expand All @@ -33,4 +33,5 @@ object Versions {

const val mockk = "1.12.0"
const val junit = "4.13.2"
const val ktlint = "0.40.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package co.anitrend.support.query.builder.buildSrc.extension
import co.anitrend.support.query.builder.buildSrc.module.Modules
import com.android.build.gradle.*
import com.android.build.gradle.api.AndroidBasePlugin
import com.android.build.gradle.api.BaseVariantOutput
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import org.gradle.api.Project
import com.diffplug.gradle.spotless.SpotlessExtension
import org.gradle.api.internal.plugins.DefaultArtifactPublicationSet
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.plugins.JavaPluginExtension
Expand Down Expand Up @@ -56,9 +56,6 @@ internal fun Project.sourceSetContainer() =
internal fun Project.javaPluginExtension() =
extensions.getByType<JavaPluginExtension>()

internal fun Project.variantOutput() =
extensions.getByType<BaseVariantOutput>()

internal fun Project.kotlinAndroidProjectExtension() =
extensions.getByType<KotlinAndroidProjectExtension>()

Expand All @@ -74,6 +71,9 @@ internal fun Project.publishingExtension() =
internal fun Project.defaultPublicationSet() =
extensions.getByType<DefaultArtifactPublicationSet>()

internal fun Project.spotlessExtension() =
extensions.getByType<SpotlessExtension>()

internal fun Project.containsAndroidPlugin(): Boolean {
return project.plugins.toList().any { plugin ->
plugin is AndroidBasePlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.anitrend.support.query.builder.buildSrc.plugins

import co.anitrend.support.query.builder.buildSrc.extension.isKotlinLibraryGroup
import co.anitrend.support.query.builder.buildSrc.plugins.components.configureAndroid
import co.anitrend.support.query.builder.buildSrc.plugins.components.configureSpotless
import co.anitrend.support.query.builder.buildSrc.plugins.components.configureDependencies
import co.anitrend.support.query.builder.buildSrc.plugins.components.configureOptions
import co.anitrend.support.query.builder.buildSrc.plugins.components.configureKotlinJvm
Expand Down Expand Up @@ -44,9 +45,10 @@ open class CorePlugin : Plugin<Project> {
target.availableExtensions()
target.availableComponents()
if (!target.isKotlinLibraryGroup())
target.configureAndroid()
target.configureAndroid()
else target.configureKotlinJvm()
target.configureDependencies()
target.configureOptions()
//target.configureSpotless()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import co.anitrend.support.query.builder.buildSrc.common.Versions
import co.anitrend.support.query.builder.buildSrc.extension.baseAppExtension
import co.anitrend.support.query.builder.buildSrc.extension.baseExtension
import co.anitrend.support.query.builder.buildSrc.extension.kotlinJvmExtension
import co.anitrend.support.query.builder.buildSrc.extension.spotlessExtension
import co.anitrend.support.query.builder.buildSrc.extension.isAppModule
import com.android.build.gradle.internal.dsl.DefaultConfig
import org.gradle.api.JavaVersion
Expand All @@ -13,6 +14,25 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import java.io.File

internal fun Project.configureSpotless() {
if (!isAppModule())
spotlessExtension().run {
kotlin {
target("**/kotlin/**/*.kt")
targetExclude(
"$buildDir/**/*.kt",
"**/androidTest/**/*.kt",
"**/test/**/*.kt",
"bin/**/*.kt"
)
ktlint(Versions.ktlint).userData(
mapOf("android" to "true")
)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
}
}

@Suppress("UnstableApiUsage")
private fun DefaultConfig.applyAdditionalConfiguration(project: Project) {
if (project.isAppModule()) {
Expand Down Expand Up @@ -100,7 +120,7 @@ internal fun Project.configureAndroid(): Unit = baseExtension().run {

tasks.withType(KotlinCompile::class.java) {
val compilerArgumentOptions = mutableListOf(
"-Xuse-experimental=kotlin.Experimental",
"-Xopt-in=kotlin.Experimental",
"-Xopt-in=kotlin.ExperimentalStdlibApi",
"-Xopt-in=kotlin.Experimental"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ private fun addAndroidPlugin(project: Project, pluginContainer: PluginContainer)
else -> {
pluginContainer.apply("maven-publish")
pluginContainer.apply("com.android.library")
pluginContainer.apply("org.jetbrains.dokka")
}
}
if (!project.isAppModule())
pluginContainer.apply("com.diffplug.spotless")
}

private fun addKotlinAndroidPlugin(project: Project, pluginContainer: PluginContainer) {
Expand Down
16 changes: 16 additions & 0 deletions spotless/copyright.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright $YEAR AniTrend
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

0 comments on commit 0298fcf

Please sign in to comment.