Skip to content

Commit

Permalink
Use new gradle plugin syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed May 10, 2022
1 parent e0bf8eb commit cbb618c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
package org.jetbrains.webwiz.generator.files

import org.jetbrains.webwiz.generator.NAN
import org.jetbrains.webwiz.generator.ProjectFile
import org.jetbrains.webwiz.generator.deleteNans
import org.jetbrains.webwiz.models.GradlePlugin
import org.jetbrains.webwiz.models.KmpLibrary
import org.jetbrains.webwiz.models.KotlinVersion
import org.jetbrains.webwiz.models.ProjectInfo
import org.jetbrains.webwiz.models.Target

class RootBuildGradle(val projectInfo: ProjectInfo) : ProjectFile {
override val path = "build.gradle.kts"
override val content: String
get() =
"""
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
${if (projectInfo.kotlinVersion == KotlinVersion.Dev) "maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")" else NAN}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${projectInfo.kotlinVersion.versionName}")
${if (projectInfo.dependencies.contains(KmpLibrary.SERIALIZATION)) "classpath(\"org.jetbrains.kotlin:kotlin-serialization:${projectInfo.kotlinVersion.versionName}\")" else NAN}
${if (projectInfo.targets.contains(Target.ANDROID)) "classpath(\"com.android.tools.build:gradle:7.1.2\")" else NAN}
${if (GradlePlugin.SQL_DELIGHT in projectInfo.gradlePlugins) "classpath(\"com.squareup.sqldelight:gradle-plugin:1.5.3\")" else NAN}
${if (GradlePlugin.REALM in projectInfo.gradlePlugins) "classpath(\"io.realm.kotlin:gradle-plugin:0.9.0\")" else NAN}
}
}
allprojects {
repositories {
google()
mavenCentral()
${if (projectInfo.kotlinVersion == KotlinVersion.Dev) "maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")" else NAN}
}
}
""".trimIndent().deleteNans()
get() = buildString {
appendLine("plugins {")
appendLine(" kotlin(\"multiplatform\").version(\"${projectInfo.kotlinVersion.versionName}\").apply(false)")
if (projectInfo.dependencies.contains(KmpLibrary.SERIALIZATION)) {
appendLine(" kotlin(\"plugin.serialization\").version(\"${projectInfo.kotlinVersion.versionName}\").apply(false)")
}
if (projectInfo.targets.contains(Target.ANDROID)) {
appendLine(" id(\"com.android.library\").version(\"7.2.0\").apply(false)")
}
if (GradlePlugin.SQL_DELIGHT in projectInfo.gradlePlugins) {
appendLine(" id(\"com.squareup.sqldelight\").version(\"1.5.3\").apply(false)")
}
if (GradlePlugin.REALM in projectInfo.gradlePlugins) {
appendLine(" id(\"io.realm.kotlin\").version(\"0.9.0\").apply(false)")
}
appendLine("}")
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package org.jetbrains.webwiz.generator.files

import org.jetbrains.webwiz.generator.NAN
import org.jetbrains.webwiz.generator.ProjectFile
import org.jetbrains.webwiz.generator.deleteNans

class SettingsGradle(val projectName: String, val moduleName: String) : ProjectFile {
class SettingsGradle(
val projectName: String,
val moduleName: String,
val addDevMaven: Boolean
) : ProjectFile {
override val path = "settings.gradle.kts"
override val content: String
get() = """
Expand All @@ -11,10 +17,20 @@ pluginManagement {
google()
gradlePluginPortal()
mavenCentral()
${if (addDevMaven) "maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")" else NAN}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
${if (addDevMaven) "maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")" else NAN}
}
}
rootProject.name = "${projectName.replace(' ', '_')}"
include(":$moduleName")
""".trimIndent()
""".trimIndent().deleteNans()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.webwiz.generator

import org.jetbrains.webwiz.generator.files.*
import org.jetbrains.webwiz.models.GradlePlugin
import org.jetbrains.webwiz.models.KotlinVersion
import org.jetbrains.webwiz.models.ProjectInfo
import org.jetbrains.webwiz.models.Target.ANDROID
import org.jetbrains.webwiz.models.isCommonNativeTargetPresent
Expand All @@ -21,7 +22,7 @@ fun ProjectInfo.generate(): List<ProjectFile> = mutableListOf<ProjectFile>().app
add(GradleWrapperJar())

add(RootBuildGradle(info))
add(SettingsGradle(projectName, moduleName))
add(SettingsGradle(projectName, moduleName, kotlinVersion == KotlinVersion.EAP))
add(GradleProperties())

add(ModuleBuildGradle(info))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ internal class ProjectBuilderTest {
google()
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/")
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/")
}
}
Expand Down

0 comments on commit cbb618c

Please sign in to comment.