I encountered an annoying issue where dependency versions had changed but the class cache wasn’t being invalidated and the source wasn’t getting rebuilt. I eventually just deleted the whole cache on the CI server and that fixed it. Wondering though if there’s a better way to have gradle cache a little less aggressively, such that when a source file changes or a dependency the build cache is invalidated.
note: using 4.4.1
here’s my build.gradle.kts
import com.github.spotbugs.SpotBugsTask
import com.github.spotbugs.SpotBugsPlugin
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import io.spring.gradle.dependencymanagement.internal.DependencyManagement
import org.gradle.api.credentials.AwsCredentials
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.repositories
import io.spring.gradle.dependencymanagement.internal.DependencyManagementSettings
import io.spring.gradle.dependencymanagement.internal.dsl.StandardDependencyManagementExtension
import org.gradle.internal.impldep.junit.runner.Version.id
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.support.illegalElementType
import org.gradle.model.internal.core.TypeCompatibilityModelProjectionSupport.description
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaProject
import sun.security.pkcs.PKCS8Key.version
import java.lang.System
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern.compile
plugins {
`java`
`java-library`
`maven-publish`
`checkstyle`
`idea`
id("com.github.spotbugs").version("1.6.0")
id("net.ltgt.errorprone").version("0.0.13")
id("io.spring.dependency-management").version("1.0.4.RELEASE")
}
repositories {
maven(System.getenv("JAR_REPOSITORY_URI"))
jcenter()
}
group = "com.xenoterracide.rpf"
version = "0.1.0-SNAPSHOT"
description = "Registration"
configurations.all({
resolutionStrategy.cacheChangingModulesFor(1, TimeUnit.MINUTES)
})
dependencyManagement {
imports {
mavenBom("com.xenoterracide:bom:0.1.0-SNAPSHOT")
}
}
// In this section you declare the dependencies for your production and test code
dependencies {
errorprone("com.google.guava:guava:latest.release")
errorprone("com.google.errorprone:error_prone_core:latest.release")
compileOnly("com.google.code.findbugs:jsr305")
compileOnly("com.google.errorprone:error_prone_annotations:latest.release")
implementation("com.xenoterracide.rpf:sec:0.1.0-SNAPSHOT")
implementation("com.xenoterracide.entities:entities-api:0.2.0-SNAPSHOT")
implementation("com.xenoterracide.entities:entities-jpa:0.2.0-SNAPSHOT")
implementation("com.xenoterracide:util:0.1.4-SNAPSHOT")
implementation("javax.jms:jms-api")
implementation("org.apache.tika:tika-core")
implementation("org.springframework.boot:spring-boot-starter-data-rest")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-hateoas")
implementation("org.springframework.session:spring-session")
implementation("commons-codec:commons-codec")
implementation("commons-io:commons-io")
implementation("org.apache.commons:commons-lang3")
implementation("org.springframework:spring-jms")
runtimeOnly("org.springframework.boot:spring-boot-configuration-processor")
runtimeOnly("org.springframework.boot:spring-boot-starter-actuator")
runtimeOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("com.google.guava:guava")
runtimeOnly("org.apache.activemq:activemq-broker")
runtimeOnly("com.xenoterracide.rpf:changeset:0.1.0-SNAPSHOT")
runtimeOnly("org.postgresql:postgresql")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.security:spring-security-test")
testCompile("com.google.code.gson:gson")
testCompile("junit:junit")
testCompile("org.hamcrest:hamcrest-library")
testCompile("com.jcabi:jcabi-matchers")
}
idea {
module {
isDownloadSources = true
isDownloadJavadoc = true
}
}
checkstyle {
toolVersion = "8.4"
sourceSets = listOf(java.sourceSets["main"])
}
spotbugs {
toolVersion = "3.1.0"
effort = "max"
reportLevel = "low"
sourceSets = listOf(java.sourceSets["main"])
}
tasks.withType<Checkstyle> {
reports {
xml.isEnabled = false
html.isEnabled = false
}
}
tasks.withType<SpotBugsTask> {
reports {
xml.isEnabled = false
}
}
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(listOf(
"-XepExcludedPaths:.*/build/generated/.*",
"-Xep:MissingOverride:ERROR",
"-Xep:Var:ERROR"
))
}
System.getenv("JRS_S3_URI")?.let {
val sourcesJar by tasks.creating(Jar::class) {
classifier = "sources"
from(java.sourceSets["main"].allSource)
}
publishing {
repositories {
maven {
url = uri(it)
credentials(AwsCredentials::class.java) {
accessKey = System.getenv("JRS_ACCESSKEYID")
secretKey = System.getenv("JRS_SECRETACCESSKEY")
}
}
}
(publications) {
"mavenJava"(MavenPublication::class) {
from(components["java"])
artifact(sourcesJar)
}
}
}
}
sorry for the verbose output but… seems necessary. currently the only thing I can think to do is add --rerun-tasks
to all my builds so that they don’t end up in this weird cache hell, here’s how they are currently run
box: openjdk:8-alpine
build:
steps:
- script:
name: gradle
code: ./gradlew -Dorg.gradle.daemon=false -g=$WERCKER_CACHE_DIR --stacktrace --info build
I pastebin-ed 3 logs because they were too big to paste here.
update experiencing similar problems locally I had to delete my cache, rerunning tasks wasn’t enough
update
set my config to this
configurations.all({
resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
})
...
implementation("com.xenoterracide:util:0.1.4-SNAPSHOT", { isChanging = true })
implementation("com.xenoterracide.entities:entities-api:0.2.0-SNAPSHOT", { isChanging = true })
implementation("com.xenoterracide.entities:entities-jpa:0.2.0-SNAPSHOT", { isChanging = true })
implementation("com.xenoterracide.rpf:sec:0.1.0-SNAPSHOT", { isChanging = true })
implementation("com.xenoterracide.rpf:sec-dtos:0.1.0-SNAPSHOT", { isChanging = true })
implementation("com.xenoterracide.rpf:constants:0.1.0-SNAPSHOT", { isChanging = true })
and still it wasn’t refetching the modules