Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import com.autonomousapps.utils.DebugAware
@SuppressWarnings('GrMethodMayBeStatic')
abstract class AbstractProject extends AbstractGradleProject {

private static final String PRINT_ADVICE = "dependency.analysis.print.build.health=true"
protected static final GradleProperties ADDITIONAL_PROPERTIES = GradleProperties.of(PRINT_ADVICE)
protected static final GradleProperties GRADLE_PROPERTIES = GradleProperties.of(
GradleProperties.JVM_ARGS,
GradleProperties.PARALLEL,
GradleProperties.BUILD_CACHE,
"dependency.analysis.print.build.health=true",
)

/** Applies the 'org.jetbrains.kotlin.jvm' plugin. */
protected static final List<Plugin> kotlinOnly = [Plugins.kotlinJvmNoVersion]
Expand Down Expand Up @@ -85,15 +89,15 @@ abstract class AbstractProject extends AbstractGradleProject {
protected GradleProject.Builder newGradleProjectBuilder(
GradleProject.DslKind dslKind = GradleProject.DslKind.GROOVY
) {
def additionalProperties = ADDITIONAL_PROPERTIES
def gradleProperties = GRADLE_PROPERTIES
// There is a Gradle bug that makes tests break when the test uses CC/IP and we're also debugging
if (!DebugAware.debug) {
additionalProperties += GradleProperties.enableConfigurationCache()
gradleProperties += GradleProperties.enableConfigurationCache()
}

return super.newGradleProjectBuilder(dslKind)
.withRootProject { r ->
r.gradleProperties += additionalProperties
r.gradleProperties = gradleProperties
r.withBuildScript { bs ->
bs.plugins(plugins.dependencyAnalysis, plugins.kotlinJvmNoApply)
}
Expand All @@ -112,7 +116,7 @@ abstract class AbstractProject extends AbstractGradleProject {
GradleProject.DslKind dslKind,
boolean withKotlin
) {
def additionalProperties = ADDITIONAL_PROPERTIES
def additionalProperties = GRADLE_PROPERTIES
// There is a Gradle bug that makes tests break when the test uses CC/IP and we're also debugging
if (!DebugAware.debug) {
additionalProperties += GradleProperties.enableConfigurationCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.autonomousapps.android

import com.autonomousapps.android.projects.AndroidAssetsProject
import com.autonomousapps.internal.android.AgpVersion
import org.gradle.util.GradleVersion

import static com.autonomousapps.advice.truth.BuildHealthSubject.buildHealth
import static com.autonomousapps.kit.truth.BuildTaskSubject.buildTasks
Expand All @@ -19,12 +18,9 @@ final class ConfigurationCacheSpec extends AbstractAndroidSpec {
def project = new AndroidAssetsProject(agpVersion as String)
gradleProject = project.gradleProject

// We use '--no-build-cache' because we're validating SUCCESS, and successive builds validate UP-TO-DATE
when: 'We build the first time'
def result = build(
gradleVersion as GradleVersion,
gradleProject.rootDir,
'buildHealth', '--configuration-cache'
)
def result = build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--no-build-cache')

then: 'buildHealth produces expected results'
assertAbout(buildHealth())
Expand All @@ -35,11 +31,7 @@ final class ConfigurationCacheSpec extends AbstractAndroidSpec {
assertAbout(buildTasks()).that(result.task(':generateBuildHealth')).succeeded()

when: 'We build again'
result = build(
gradleVersion as GradleVersion,
gradleProject.rootDir,
'buildHealth', '--configuration-cache'
)
result = build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then: 'buildHealth produces expected results'
assertAbout(buildHealth())
Expand All @@ -55,7 +47,7 @@ final class ConfigurationCacheSpec extends AbstractAndroidSpec {
assertThat(result).output().contains('Configuration cache entry reused.')
}

where: 'Min support for this is Gradle 7.5'
where:
[gradleVersion, agpVersion] << gradleAgpMatrix()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ClassifiersSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -31,8 +31,8 @@ final class ClassifiersSpec extends AbstractJvmSpec {
def project = new TransitiveClassifierTestProject(variant)
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
when: // TODO(tsr): this test fails if the build cache is enabled

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: fix this in a follow-up

build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--no-build-cache')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -35,7 +35,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -49,8 +49,8 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
def project = new FeatureVariantTestProject(producerCodeInFeature, additionalCapabilities)
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
when: // TODO(tsr): this test fails if the build cache is enabled

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: fix this in a follow-up

build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--no-build-cache')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -69,7 +69,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -84,7 +84,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -99,7 +99,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -114,7 +114,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)
Expand All @@ -129,7 +129,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -143,8 +143,8 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
def project = new FeatureVariantTestProject(true, false, true)
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
when: // TODO(tsr): this test fails if the build cache is enabled

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: fix this in a follow-up

build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--no-build-cache')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -159,7 +159,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -177,7 +177,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
buildAndFail(gradleVersion, gradleProject.rootDir, 'buildHealth')
buildAndFail(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth())
Expand All @@ -197,7 +197,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)
Expand All @@ -215,7 +215,7 @@ final class CustomSourceSetSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, 'buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@
package com.autonomousapps.jvm

import com.autonomousapps.jvm.projects.GraphViewCacheProject
import org.gradle.util.GradleVersion

import static com.autonomousapps.kit.truth.BuildTaskSubject.buildTasks
import static com.autonomousapps.utils.Runner.build
import static com.google.common.truth.Truth.assertAbout

final class GraphViewCacheSpec extends AbstractJvmSpec {

def "graphViewTask is sensitive to changing dependencies"() {
def "graphViewTask is sensitive to changing dependencies (#gradleVersion)"() {
given:
def project = new GraphViewCacheProject()
gradleProject = project.gradleProject
def task = ':proj:graphViewMain'
def gradleVersion = GradleVersion.current()

when: 'First build'
def result = build(gradleVersion, gradleProject.rootDir, task, '--build-cache', '-Dv=0.3.0-alpha27')
def result = build(gradleVersion, gradleProject.rootDir, task, '-Dv=0.3.0-alpha27')

then: 'Task executed'
assertAbout(buildTasks()).that(result.task(task)).succeeded()

when: 'Second build'
result = build(gradleVersion, gradleProject.rootDir, 'clean', task, '--build-cache', '-Dv=0.3.0-alpha28')
result = build(gradleVersion, gradleProject.rootDir, 'clean', task, '-Dv=0.3.0-alpha28')

then: 'Task executed (not FROM_CACHE)'
assertAbout(buildTasks()).that(result.task(task)).succeeded()

where:
gradleVersion << gradleVersions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class GraphViewProjectEdgeCacheSpec extends AbstractJvmSpec {
def task = ':consumer:graphViewMain'

when: 'First build, without the direct -> transitive edge'
def result = build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--build-cache')
def result = build(gradleVersion, gradleProject.rootDir, ':buildHealth')
def graphCompilePath = OutputPathsKt.getGraphCompilePath('main')
def graphOutput = gradleProject.singleArtifact('consumer', graphCompilePath).asFile

Expand All @@ -28,7 +28,7 @@ final class GraphViewProjectEdgeCacheSpec extends AbstractJvmSpec {
assertThat(graphOutput.text).doesNotContain(':transitive')

when: 'Second build, after the direct project adds an api dependency on transitive'
result = build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth', '--build-cache', '-Dedge=true')
result = build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth', '-Dedge=true')

then: 'Task executed (not FROM_CACHE) and transitive is in the graph'
assertAbout(buildTasks()).that(result.task(task)).succeeded()
Expand All @@ -44,13 +44,13 @@ final class GraphViewProjectEdgeCacheSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when: 'First build, without the direct -> transitive edge'
build(gradleVersion, gradleProject.rootDir, ':buildHealth', '--build-cache')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then: 'There is no advice'
assertThat(actualProjectAdvice('consumer').dependencyAdvice).isEmpty()

when: 'Second build, after the direct project adds an api dependency on transitive'
build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth', '--build-cache', '-Dedge=true')
build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth', '-Dedge=true')

then: 'Advises declaring the used transitive dependency directly'
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class IncludedBuildSpec extends AbstractJvmSpec {
* Only since Gradle 8.2 we can use the more precise BuildIdentifier.buildPath (instead of BuildIdentifier.name).
* That's why the expectations in this test differ depending on Gradle version.
*/
private final static isAtLeastGradle82(GradleVersion version) {
private final static isAtLeastGradle82(GradleVersion version) {
version >= GradleVersion.version("8.2")
}

Expand Down Expand Up @@ -151,19 +151,19 @@ final class IncludedBuildSpec extends AbstractJvmSpec {
gradleProject = project.gradleProject

when:
build(gradleVersion, gradleProject.rootDir, '--build-cache', ':buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then:
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)

when: 'Running again - UP-TO-DATE'
build(gradleVersion, gradleProject.rootDir, '--build-cache', ':buildHealth')
build(gradleVersion, gradleProject.rootDir, ':buildHealth')

then: 'Result is the same'
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)

when: 'Running again - FROM-CACHE'
build(gradleVersion, gradleProject.rootDir, '--build-cache', 'clean', ':buildHealth')
build(gradleVersion, gradleProject.rootDir, 'clean', ':buildHealth')

then: 'Result is the same'
assertThat(project.actualBuildHealth()).containsExactlyElementsIn(project.expectedBuildHealth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ final class BuildLogicVersionCatalogProject extends AbstractProject {
}
.withIncludedBuild(BUILD_LOGIC) { buildLogic ->
buildLogic.withRootProject { r ->
r.gradleProperties += ADDITIONAL_PROPERTIES
r.withSettingsScript { s ->
s.additions = """\
dependencyResolutionManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.autonomousapps.AbstractProject
import com.autonomousapps.kit.GradleProject
import com.autonomousapps.kit.Source
import com.autonomousapps.kit.gradle.Dependency
import com.autonomousapps.kit.gradle.GradleProperties
import com.autonomousapps.kit.gradle.Java
import com.autonomousapps.kit.gradle.dependencies.Plugins
import com.autonomousapps.model.Advice
Expand Down Expand Up @@ -105,7 +104,6 @@ final class CompileOnlyTransitiveProject extends AbstractProject {
.withIncludedBuild('other') { included ->
included
.withRootProject { r ->
r.gradleProperties += GradleProperties.enableConfigurationCache() + ADDITIONAL_PROPERTIES
r.withBuildScript { bs ->
bs.plugins = [Plugins.dependencyAnalysis, Plugins.kotlinJvmNoApply]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ final class IncludedBuildWithAnnotationProcessorProject extends AbstractProject
}
.withIncludedBuild('processor-build') { second ->
second.withRootProject { r ->
r.gradleProperties += GradleProperties.enableConfigurationCache() + ADDITIONAL_PROPERTIES
r.withBuildScript { bs ->
bs.plugins = [Plugins.dependencyAnalysis, Plugins.kotlinJvmNoApply]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ final class IncludedBuildWithSubprojectsProject extends AbstractProject {
}
.withIncludedBuild('second-build') { second ->
second.withRootProject { r ->
r.gradleProperties += GradleProperties.enableConfigurationCache() + ADDITIONAL_PROPERTIES
r.withBuildScript { bs ->
bs.plugins = [Plugins.dependencyAnalysis, Plugins.kotlinJvmNoApply]
}
Expand Down
Loading