Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new project specs for Empty and Basic Activity Android Applications #120

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed unified-prototype/build.gradle.kts
Empty file.
7 changes: 5 additions & 2 deletions unified-prototype/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=512m
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=1g
android.useAndroidX=true

# Supress "The selected Xcode version (15.4) is higher than the maximum known to the Kotlin Gradle Plugin."
kotlin.apple.xcodeCompatibility.nowarn=true
2 changes: 1 addition & 1 deletion unified-prototype/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-8.11-20240815222552+0000-bin.zip
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-8.11-20240917195623+0000-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion unified-prototype/java-util/build.gradle.dcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
javaLibrary {
javaVersion = 11
javaVersion = 17
}
206 changes: 82 additions & 124 deletions unified-prototype/kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion unified-prototype/kotlin-util/build.gradle.dcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kotlinLibrary {
targets {
jvm {
jdkVersion = 11
jdkVersion = 17
}
nodeJs()
macOsArm64()
Expand Down
4 changes: 2 additions & 2 deletions unified-prototype/settings.gradle.dcl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ rootProject.name = "unified-prototype"

defaults {
androidLibrary {
jdkVersion = 11
jdkVersion = 17
compileSdk = 34
}

androidApplication {
jdkVersion = 11
jdkVersion = 17
compileSdk = 34
}
}
Expand Down
4 changes: 2 additions & 2 deletions unified-prototype/testbed-jvm-application/build.gradle.dcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jvmApplication {
}

targets {
java(11) {
java(21) {
dependencies {
// Requires java 11
// This library will only be available for Java 21 targets
implementation("org.hibernate.orm:hibernate-core:6.4.2.Final")
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example;

public class TwentyOne implements Interface {
@Override
public String getValue() {
return "Java 21. Hibernate version is " + org.hibernate.Version.getVersionString();
}
}
4 changes: 2 additions & 2 deletions unified-prototype/testbed-jvm-library/build.gradle.dcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ jvmLibrary {
}

targets {
java(11) {
java(21) {
dependencies {
// Requires java 11
// This library will only be available for Java 21 targets
implementation("org.hibernate.orm:hibernate-core:6.4.2.Final")
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.example;

public class Eleven implements Interface {
public class TwentyOne implements Interface {

@Override
public String getValue() {
var result = "Java 11. The value is " + new Common().getValue() + ". Hibernate version is " + org.hibernate.Version.getVersionString();
var result = "Java 21. The value is " + new Common().getValue() + ". Hibernate version is " + org.hibernate.Version.getVersionString();
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.example.TwentyOne
21 changes: 12 additions & 9 deletions unified-prototype/unified-plugin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[versions]
# Kotlin Libs
# Find latest version at: https://kotlinlang.org/docs/releases.html#release-details
kotlin = "1.9.23"
ksp = "1.9.23-1.0.20"
kotlin = "2.0.20"
ksp = "2.0.20-1.0.25"

# Android Libs
# Find latest version at: https://developer.android.com/reference/tools/gradle-api
android = "8.3.0"
androidTools = "31.3.0"
baselineProfile = "1.2.2"
firebaseCrashlytics = "2.9.9"
android = "8.5.2"
androidTools = "31.6.0"
baselineProfile = "1.3.0"
firebaseCrashlytics = "3.0.2"
firebasePerf = "1.4.2"
gms = "4.4.1"
hilt = "2.50"
gms = "4.4.2"
hilt = "2.51"
room = "2.6.1"

#Other Libs
apache-commons = "3.3.1"
apache-commons = "3.14.0"
dependency-guard = "0.4.3"
truth = "1.4.2"
protobuf = "0.9.4"
Expand Down Expand Up @@ -45,8 +45,11 @@ room-plugin = { module = "androidx.room:room-gradle-plugin", version.ref = "room

#Other Libs
apache-commons-lang = { module = "org.apache.commons:commons-lang3", version.ref = "apache-commons" }
compose-compiler-plugin = { group = "org.jetbrains.kotlin", name = "compose-compiler-gradle-plugin", version.ref = "kotlin" }
dependency-guard-plugin = { module = "com.dropbox.dependency-guard:com.dropbox.dependency-guard.gradle.plugin", version.ref = "dependency-guard"}
oss-licenses-plugin = { group = "com.google.android.gms", name = "oss-licenses-plugin", version.ref = "oss-licenses" }
protobuf-plugin = { module = "com.google.protobuf:protobuf-gradle-plugin", version.ref = "protobuf" }
roborazzi-plugin = { module = "io.github.takahirom.roborazzi:roborazzi-gradle-plugin", version.ref = "roborazzi" }
truth = { module = "com.google.truth:truth", version.ref = "truth" }

[plugins]
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gradle.integtests.fixtures

import org.gradle.internal.nativeintegration.console.TestOverrideConsoleDetector
import org.gradle.plugin.management.internal.autoapply.AutoAppliedPluginHandler
import org.gradle.test.fixtures.AbstractSpecification
import org.gradle.testkit.runner.GradleRunner
Expand All @@ -9,13 +8,19 @@ import org.gradle.testkit.runner.GradleRunner
* Base class for tests that generate, build, and validate (via run, or something else) included project init specifications.
*/
abstract class AbstractProjectInitSpecification extends AbstractSpecification {
private static final String DECLARATIVE_PROTOTYPE_VERSION = "0.1.11"
private static final String DECLARATIVE_PROTOTYPE_VERSION = "use.local.version"

protected File projectDir = file("new-project").tap { mkdirs() }

abstract String getPluginId()
protected abstract String getProjectSpecType()
protected abstract String getEcosystemPluginId()

// TODO: add project type method here, specify type of project to be generated (need to update Gradle wrapper to new nightly containing getType() first)
/**
* Perform additional validation on the built project, perhaps by running it and verifying the output.
* <p>
* Defaults to No-Op.
*/
protected void validateBuiltProject() {}

def "can generate project from init project spec"() {
when:
Expand All @@ -25,39 +30,28 @@ abstract class AbstractProjectInitSpecification extends AbstractSpecification {
canBuildGeneratedProject()

and:
validateGeneratedProjectRuns()
validateBuiltProject()
}

protected void runInitWithPluginAsInitProjectSpecSupplier() {
def args = ["init",
"-D${AutoAppliedPluginHandler.INIT_PROJECT_SPEC_SUPPLIERS_PROP}=$pluginId:$DECLARATIVE_PROTOTYPE_VERSION",
"-D${TestOverrideConsoleDetector.INTERACTIVE_TOGGLE}=true"] as String[]
def initInvocation = ["-D${AutoAppliedPluginHandler.INIT_PROJECT_SPEC_SUPPLIERS_PROP}=$ecosystemPluginId:$DECLARATIVE_PROTOTYPE_VERSION",
"init",
"--type", "$projectSpecType"] as String[]

result = GradleRunner.create()
.withProjectDir(projectDir)
.withArguments(args)
.withPluginClasspath()
.withDebug(true)
.withArguments(initInvocation)
.forwardOutput()
.build()
}

protected void canBuildGeneratedProject() {
result = GradleRunner.create()
.withProjectDir(projectDir)
.withPluginClasspath()
.withArguments("build")
.withDebug(true)
.forwardOutput()
.build()
}

protected void validateGeneratedProjectRuns() {
result = GradleRunner.create()
.withProjectDir(projectDir)
.withArguments(":app:run")
.forwardOutput()
.build()

assert result.output.contains("Hello World!")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation(libs.firebase.perf.plugin)
implementation(libs.firebase.crashlytics.plugin)
implementation(libs.oss.licenses.plugin)
implementation(libs.compose.compiler.plugin)

implementation(libs.apache.commons.lang)
implementation(libs.android.tools.common)
Expand Down Expand Up @@ -73,8 +74,6 @@ gradlePlugin {
tags = setOf("declarative-gradle", "android")
}
}

testSourceSet(sourceSets.getByName("integTest"))
}

// Compile against Java 17 since Android requires Java 17 at minimum
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gradle.api.experimental.android

import org.gradle.integtests.fixtures.AbstractProjectInitSpecification

abstract class AbstractAndroidInitProjectSpec extends AbstractProjectInitSpecification {
@Override
protected String getEcosystemPluginId() {
return "org.gradle.experimental.android-ecosystem"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gradle.api.experimental.android

class AndroidApplicationBasicActivityInitProjectSpec extends AbstractAndroidInitProjectSpec {
@Override
String getProjectSpecType() {
return "declarative-android-application-project-with-basic-activity"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gradle.api.experimental.android

class AndroidApplicationEmptyActivityInitProjectSpec extends AbstractAndroidInitProjectSpec {
@Override
String getProjectSpecType() {
return "declarative-android-application-project-with-empty-activity"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.gradle.api.experimental.android

import org.gradle.integtests.fixtures.AbstractProjectInitSpecification

class AndroidApplicationInitProjectSpec extends AbstractProjectInitSpecification {
class AndroidApplicationInitProjectSpec extends AbstractAndroidInitProjectSpec {
@Override
String getPluginId() {
return "org.gradle.experimental.android-ecosystem"
protected String getProjectSpecType() {
return "declarative-android-application-project"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ class AndroidApplicationSpec extends AbstractSpecification {
<manifest/>
"""

file("gradle.properties").text = """
android.useAndroidX=true
"""

expect:
succeeds(":build")
}
Expand Down Expand Up @@ -94,5 +90,9 @@ class AndroidApplicationSpec extends AbstractSpecification {

rootProject.name = "example"
"""

file("gradle.properties").text = """
android.useAndroidX=true
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ class AndroidLibrarySpec extends AbstractSpecification {
fails(":compileReleaseKotlin")
}

def 'can create a library with compose enabled'() {
given:
buildFile << """
androidLibrary {
jdkVersion = 17
compileSdk = 34

namespace = "org.example.android.library"

compose {
enabled = true
}
}
"""

expect:
succeeds(":build")
file("build/outputs/aar/example-debug.aar").exists()
file("build/outputs/aar/example-release.aar").exists()
}

def setup() {
settingsFile << """
plugins {
Expand All @@ -139,5 +160,9 @@ class AndroidLibrarySpec extends AbstractSpecification {

rootProject.name = "example"
"""

file("gradle.properties").text = """
android.useAndroidX=true
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ protected void configureHilt(Project project, AndroidSoftware dslModel) {

// Add support for KSP
project.getPlugins().apply("com.google.devtools.ksp");
project.getDependencies().add("ksp", "com.google.dagger:hilt-android-compiler:2.50");
project.getDependencies().add("ksp", "com.google.dagger:hilt-android-compiler:2.52");

// Add support for Hilt
project.getPlugins().apply("dagger.hilt.android.plugin");
project.getDependencies().add("implementation", "com.google.dagger:hilt-android:2.50");
project.getDependencies().add("implementation", "com.google.dagger:hilt-android:2.52");

project.getDependencies().add("kspTest", "com.google.dagger:hilt-android-compiler:2.50");
project.getDependencies().add("kspTest", "com.google.dagger:hilt-android-compiler:2.52");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.gradle.api.experimental.buildinit;
package org.gradle.api.experimental.android.buildinit;

import org.gradle.api.experimental.buildinit.StaticProjectGenerator;
import org.gradle.api.experimental.buildinit.StaticProjectSpec;
import org.gradle.buildinit.projectspecs.InitProjectGenerator;
import org.gradle.buildinit.projectspecs.InitProjectSource;
import org.gradle.buildinit.projectspecs.InitProjectSpec;
Expand All @@ -14,7 +16,9 @@ public final class AndroidProjectSource implements InitProjectSource {
@Override
public List<InitProjectSpec> getProjectSpecs() {
return List.of(
new StaticProjectSpec("android-application", "Declarative Android Application Project")
new StaticProjectSpec("android-application", "Declarative Android Application Project"),
new StaticProjectSpec("android-application-basic-activity", "Declarative Android Application Project with Basic Activity"),
new StaticProjectSpec("android-application-empty-activity", "Declarative Android Application Project with Empty Activity")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* This package uses the experimental API for dynamically providing project specifications for Gradle's {@code init} build task.
*/
@org.gradle.api.NonNullApi
package org.gradle.api.experimental.buildinit;
package org.gradle.api.experimental.android.buildinit;
Loading
Loading