Skip to content

Commit

Permalink
Merge pull request #97 from gradle/tt/conventions-are-not-optional
Browse files Browse the repository at this point in the history
Upgrade the Gradle wrapper to the latest nightly, requiring conventions to be explicitly enabled in projects
  • Loading branch information
tresat committed Jun 14, 2024
2 parents 26ffa45 + 15f5117 commit e678801
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 67 deletions.
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\:https://services.gradle.org/distributions-snapshots/gradle-8.9-branch-gh_declarative_convention_rules-20240520154301+0000-bin.zip
distributionUrl=https\:https://services.gradle.org/distributions-snapshots/gradle-8.10-20240614182247+0000-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import spock.lang.Specification

import static org.gradle.testkit.runner.TaskOutcome.FAILED
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

class AbstractSpecification extends Specification {
Expand Down Expand Up @@ -49,4 +50,15 @@ class AbstractSpecification extends Specification {
assert result.task(task).outcome == SUCCESS
}
}

def fails(String... tasks) {
result = GradleRunner.create()
.withProjectDir(getTestDirectory())
.withArguments(tasks)
.withPluginClasspath()
.run()
tasks.each { task ->
assert result.task(task).outcome == FAILED
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,88 @@ class AndroidLibrarySpec extends AbstractSpecification {
file("build/outputs/aar/example-release.aar").exists()
}

def 'given conventions with an optional extension block that configures but does not enable that extension, can create a basic android library that enables that extension'() {
given:
file("gradle.properties") << """
android.useAndroidX=true
"""

buildFile << """
androidLibrary {
hilt {
enabled = true
}
}
"""

settingsFile << """
conventions {
androidLibrary {
jdkVersion = 17
compileSdk = 34
namespace = "org.example.android.library"
hilt {
enabled = false
}
}
}
"""

file("src/main/kotlin/org/example/TestHiltSupport.kt") << """
package org.example
import dagger.Module // Should be able to import this class
class TestSupport {}
"""

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

def 'given conventions with an optional extension block that configures but does not enable that extension, can not create a basic android library that uses that extension without explicitly enabling it'() {
given:
file("gradle.properties") << """
android.useAndroidX=true
"""

buildFile << """
androidLibrary {
hilt {}
}
"""

settingsFile << """
conventions {
androidLibrary {
jdkVersion = 17
compileSdk = 34
namespace = "org.example.android.library"
hilt {
enabled = false
}
}
}
"""

file("src/main/kotlin/org/example/TestHiltSupport.kt") << """
package org.example
import dagger.Module // Should be able to import this class
class TestSupport {}
"""

expect:
fails(":compileReleaseKotlin")
}

def setup() {
settingsFile << """
plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,39 @@ public interface AndroidSoftware extends HasLinting {

@Configuring
default void kotlinSerialization(Action<? super KotlinSerialization> action) {
KotlinSerialization kotlinSerialization = getKotlinSerialization();
kotlinSerialization.getEnabled().set(true);
action.execute(kotlinSerialization);
action.execute(getKotlinSerialization());
}

@Nested
Compose getCompose();

@Configuring
default void compose(Action<? super Compose> action) {
Compose compose = getCompose();
compose.getEnabled().set(true);
action.execute(compose);
action.execute(getCompose());
}

@Nested
CoreLibraryDesugaring getCoreLibraryDesugaring();

@Configuring
default void coreLibraryDesugaring(Action<? super CoreLibraryDesugaring> action) {
CoreLibraryDesugaring coreLibraryDesugaring = getCoreLibraryDesugaring();
coreLibraryDesugaring.getEnabled().set(true);
action.execute(coreLibraryDesugaring);
action.execute(getCoreLibraryDesugaring());
}

@Nested
Hilt getHilt();

@Configuring
default void hilt(Action<? super Hilt> action) {
Hilt hilt = getHilt();
hilt.getEnabled().set(true);
action.execute(hilt);
action.execute(getHilt());
}

@Nested
Room getRoom();

@Configuring
default void room(Action<? super Room> action) {
Room room = getRoom();
room.getEnabled().set(true);
action.execute(room);
action.execute(getRoom());
}

@Nested
Expand All @@ -122,9 +112,7 @@ default void testing(Action<? super Testing> action) {

@Configuring
default void feature(Action<? super Feature> action) {
Feature feature = getFeature();
feature.getEnabled().set(true);
action.execute(feature);
action.execute(getFeature());
}

/**
Expand All @@ -136,19 +124,15 @@ default void feature(Action<? super Feature> action) {

@Configuring
default void licenses(Action<? super Licenses> action) {
Licenses licenses = getLicenses();
licenses.getEnabled().set(true);
action.execute(licenses);
action.execute(getLicenses());
}

@Nested
BaselineProfile getBaselineProfile();

@Configuring
default void baselineProfile(Action<? super BaselineProfile> action) {
BaselineProfile baselineProfile = getBaselineProfile();
baselineProfile.getEnabled().set(true);
action.execute(baselineProfile);
action.execute(getBaselineProfile());
}

@Override
Expand All @@ -157,8 +141,6 @@ default void baselineProfile(Action<? super BaselineProfile> action) {

@Configuring
default void lint(Action<? super Lint> action) {
Lint lint = getLint();
lint.getEnabled().set(true);
action.execute(lint);
action.execute(getLint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ default ProguardFile defaultProguardFile(Action<? super ProguardFile> configure)

@Configuring
default void baselineProfile(Action<? super BaselineProfile> action) {
BaselineProfile baselineProfile = getBaselineProfile();
baselineProfile.getEnabled().set(true);
action.execute(baselineProfile);
action.execute(getBaselineProfile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,23 @@ default void buildTypes(Action<? super AndroidApplicationBuildTypes> action) {

@Configuring
default void dependencyGuard(Action<? super DependencyGuard> action) {
DependencyGuard dependencyGuard = getDependencyGuard();
dependencyGuard.getEnabled().set(true);
action.execute(dependencyGuard);
action.execute(getDependencyGuard());
}

@Nested
Firebase getFirebase();

@Configuring
default void firebase(Action<? super Firebase> action) {
Firebase firebase = getFirebase();
firebase.getEnabled().set(true);
action.execute(firebase);
action.execute(getFirebase());
}

@Nested
Flavors getFlavors();

@Configuring
default void flavors(Action<? super Flavors> action) {
Flavors flavors = getFlavors();
flavors.getEnabled().set(true);
action.execute(flavors);
action.execute(getFlavors());
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import org.gradle.declarative.dsl.model.annotations.Configuring;
import org.gradle.declarative.dsl.model.annotations.Restricted;

@Restricted
public interface BaselineProfile {
/**
* Internal property purposely not exposed to the DSL.
*/
@Restricted
Property<Boolean> getEnabled();

@Restricted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

@Restricted
public interface Licenses {
/**
* Internal property purposely not exposed to the DSL.
*/
@Restricted
Property<Boolean> getEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ public interface Testing {

@Configuring
default void jacoco(Action<? super Jacoco> action) {
Jacoco jacoco = getJacoco();
action.execute(jacoco);
jacoco.getEnabled().set(true);
action.execute(getJacoco());
}

@Nested
Roborazzi getRoborazzi();

@Configuring
default void roborazzi(Action<? super Roborazzi> action) {
Roborazzi roborazzi = getRoborazzi();
roborazzi.getEnabled().set(true);
action.execute(roborazzi);
action.execute(getRoborazzi());
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ default void buildTypes(Action<? super AndroidLibraryBuildTypes> action) {

@Configuring
default void protobuf(Action<? super Protobuf> action) {
Protobuf protobuf = getProtobuf();
protobuf.getEnabled().set(true);
action.execute(protobuf);
action.execute(getProtobuf());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
@Restricted
public interface Feature {
/**
* Internal property purposely not exposed to the DSL.
*/
@Restricted
Property<Boolean> getEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

@Restricted
public interface Flavors {
/**
* Internal property purposely not exposed to the DSL.
*/
@Restricted
Property<Boolean> getEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

@Restricted
public interface Lint {
/**
* Internal property purposely not exposed to the DSL.
*/
@Restricted
Property<Boolean> getEnabled();

@Restricted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public interface KotlinJvmLibrary extends HasJavaTarget, HasLibraryDependencies,

@Configuring
default void lint(Action<? super Lint> action) {
Lint lint = getLint();
lint.getEnabled().set(true);
action.execute(lint);
action.execute(getLint());
}

@Nested
Expand Down

0 comments on commit e678801

Please sign in to comment.