Skip to content

Commit

Permalink
Fix copyMockMethodDispatcher task (mockito#2840)
Browse files Browse the repository at this point in the history
The task was incorrectly defining inputs and outputs, resulting in the task being marked 'UP-TO-DATE' and not re-running when the input changed or the output was removed.

The task now copies the 'raw' file into a new output directory and includes that directory in the jar.

This corrects the task inputs and outputs, while also avoiding warnings about shared output directories.
  • Loading branch information
big-andy-coates committed Dec 27, 2022
1 parent aa6c339 commit bd9947f
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions gradle/mockito-core/inline-mock.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
task copyMockMethodDispatcher {
tasks.register('copyMockMethodDispatcher', Copy) {
dependsOn compileJava
outputs.files files("${sourceSets.main.java.outputDir}/org/mockito/internal/creation/bytebuddy/inject")
.asFileTree
.matching { include "*.raw" }
.files
.collect { "${buildDir}/${it.name}" }

doLast {
copy {
from "${sourceSets.main.java.outputDir}/org/mockito/internal/creation/bytebuddy/inject"
into "${sourceSets.main.java.outputDir}/org/mockito/internal/creation/bytebuddy/inject"
include 'MockMethodDispatcher.class'
rename { String fileName ->
fileName.replace('.class', '.raw')
}
}
}
from "${sourceSets.main.java.classesDirectory.get()}/org/mockito/internal/creation/bytebuddy/inject/MockMethodDispatcher.class"
into layout.buildDirectory.dir("generated/resources/inline/org/mockito/internal/creation/bytebuddy/inject")

rename '(.+)\\.class', '$1.raw'
}
classes.dependsOn(copyMockMethodDispatcher)

sourceSets.main {
resources {
output.dir(layout.buildDirectory.dir("generated/resources/inline"))
}
}

jar {
exclude("org/mockito/internal/creation/bytebuddy/inject/package-info.class")
exclude("org/mockito/internal/creation/bytebuddy/inject/MockMethodDispatcher.class")
Expand Down

0 comments on commit bd9947f

Please sign in to comment.