-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom version or coordinates for Compose compiler (#207)
Since this project does not build a Kotlin compiler plugin, we should not be forced to do a release for new versions of Kotlin. This property will allow consumers to upgrade their Kotlin version by specifying a newer JetBrains Compose compiler version, or a totally different set of Maven coordinates for a custom Compose compiler artifact.
- Loading branch information
1 parent
ac346eb
commit c82b717
Showing
13 changed files
with
234 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
mosaic-gradle-plugin/src/main/kotlin/com/jakewharton/mosaic/gradle/MosaicExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.jakewharton.mosaic.gradle | ||
|
||
import org.gradle.api.provider.Property | ||
|
||
interface MosaicExtension { | ||
/** | ||
* The version of the JetBrains Compose compiler to use, or a Maven coordinate triple of | ||
* the custom Compose compiler to use. | ||
* | ||
* Example: using a custom version of the JetBrains Compose compiler | ||
* ```kotlin | ||
* redwood { | ||
* kotlinCompilerPlugin.set("1.4.8") | ||
* } | ||
* ``` | ||
* | ||
* Example: using a custom Maven coordinate for the Compose compiler | ||
* ```kotlin | ||
* redwood { | ||
* kotlinCompilerPlugin.set("com.example:custom-compose-compiler:1.0.0") | ||
* } | ||
* ``` | ||
*/ | ||
val kotlinCompilerPlugin: Property<String> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../../../../../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
mosaic-gradle-plugin/src/test/fixture/custom-compiler-coordinates/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
buildscript { | ||
dependencies { | ||
classpath "com.jakewharton.mosaic:mosaic-gradle-plugin:$mosaicVersion" | ||
classpath libs.kotlin.gradlePlugin | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${projectDir.absolutePath}/../../../../../build/testMaven" | ||
} | ||
mavenCentral() | ||
} | ||
} | ||
|
||
apply plugin: 'org.jetbrains.kotlin.jvm' | ||
apply plugin: 'com.jakewharton.mosaic' | ||
|
||
mosaic { | ||
// Use the AndroidX Compose compiler instead of JetBrains Compose compiler. | ||
kotlinCompilerPlugin = libs.androidx.compose.compiler.get().toString() | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${projectDir.absolutePath}/../../../../../build/testMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} |
7 changes: 7 additions & 0 deletions
7
mosaic-gradle-plugin/src/test/fixture/custom-compiler-coordinates/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../../../../../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
mosaic-gradle-plugin/src/test/fixture/custom-compiler-invalid/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
buildscript { | ||
dependencies { | ||
classpath "com.jakewharton.mosaic:mosaic-gradle-plugin:$mosaicVersion" | ||
classpath libs.kotlin.gradlePlugin | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${projectDir.absolutePath}/../../../../../build/testMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} | ||
} | ||
|
||
apply plugin: 'org.jetbrains.kotlin.jvm' | ||
apply plugin: 'com.jakewharton.mosaic' | ||
|
||
mosaic { | ||
kotlinCompilerPlugin = 'wrong:format' | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${projectDir.absolutePath}/../../../../../build/testMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} |
7 changes: 7 additions & 0 deletions
7
mosaic-gradle-plugin/src/test/fixture/custom-compiler-invalid/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../../../../../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
mosaic-gradle-plugin/src/test/fixture/custom-compiler-version/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
buildscript { | ||
ext.kotlinVersion = '1.8.20' | ||
|
||
dependencies { | ||
classpath "com.jakewharton.mosaic:mosaic-gradle-plugin:$mosaicVersion" | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${projectDir.absolutePath}/../../../../../build/testMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} | ||
} | ||
|
||
if (kotlinVersion == libs.kotlin.gradlePlugin.get().version) { | ||
throw RuntimeException("This test requires a different version of Kotlin then the Mosaic build") | ||
} | ||
|
||
apply plugin: 'org.jetbrains.kotlin.jvm' | ||
apply plugin: 'com.jakewharton.mosaic' | ||
|
||
mosaic { | ||
// Use the JetBrains Compose compiler version for the version of Kotlin used by this project. | ||
kotlinCompilerPlugin = '1.4.8' | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://${projectDir.absolutePath}/../../../../../build/testMaven" | ||
} | ||
mavenCentral() | ||
google() | ||
} |
7 changes: 7 additions & 0 deletions
7
mosaic-gradle-plugin/src/test/fixture/custom-compiler-version/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files('../../../../../gradle/libs.versions.toml')) | ||
} | ||
} | ||
} |
55 changes: 32 additions & 23 deletions
55
mosaic-gradle-plugin/src/test/kotlin/com/jakewharton/mosaic/gradle/FixtureTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
package com.jakewharton.mosaic.gradle | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import java.io.File | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import org.junit.runners.Parameterized.Parameters | ||
import java.io.File | ||
|
||
@RunWith(Parameterized::class) | ||
class FixtureTest( | ||
private val fixtureName: String, | ||
) { | ||
companion object { | ||
@JvmStatic | ||
@Parameters(name = "{0}") | ||
fun parameters() = listOf( | ||
arrayOf("counter"), | ||
class FixtureTest { | ||
@Test fun counter() { | ||
fixture("counter").build() | ||
} | ||
|
||
@Test fun customCompilerCoordinates() { | ||
fixture("custom-compiler-coordinates").build() | ||
} | ||
|
||
@Test fun customCompilerInvalid() { | ||
val result = fixture("custom-compiler-invalid").buildAndFail() | ||
assertThat(result.output).contains( | ||
""" | ||
|Illegal format of 'mosaic.kotlinCompilerPlugin' property. | ||
|Expected format: either '<VERSION>' or '<GROUP_ID>:<ARTIFACT_ID>:<VERSION>' | ||
|Actual value: 'wrong:format' | ||
""".trimMargin(), | ||
) | ||
} | ||
|
||
private val fixturesDir = File("src/test/fixture") | ||
private fun versionProperty() = "-PmosaicVersion=$mosaicVersion" | ||
@Test fun customCompilerVersion() { | ||
fixture("custom-compiler-version").build() | ||
} | ||
|
||
@Test fun todo() { | ||
val fixtureDir = File(fixturesDir, fixtureName) | ||
val gradleRoot = File(fixtureDir, "gradle").also { it.mkdir() } | ||
File("../gradle").copyRecursively(File(gradleRoot.path), true) | ||
private fun fixture( | ||
name: String, | ||
tasks: Array<String> = arrayOf("clean", "build"), | ||
): GradleRunner { | ||
val fixtureDir = File("src/test/fixture", name) | ||
val gradleWrapper = File(fixtureDir, "gradle/wrapper").also { it.mkdirs() } | ||
File("../gradle/wrapper").copyRecursively(File(gradleWrapper.path), true) | ||
|
||
GradleRunner.create() | ||
return GradleRunner.create() | ||
.withProjectDir(fixtureDir) | ||
.withArguments("clean", "build", "--stacktrace", versionProperty()) | ||
.withDebug(true) // Run in-process for speed. | ||
.build() | ||
.withArguments(*tasks, "--stacktrace", "-PmosaicVersion=$mosaicVersion") | ||
.withDebug(true) | ||
} | ||
} |