Skip to content

Broken build: MockMethodDispatcher.raw not being built #2839

@big-andy-coates

Description

@big-andy-coates

I've noticed that the build can get into a bad state locally, with MockMethodDispatcher.raw not being rebuilt if it's missing.

This is because the copyMockMethodDispatcher task defined in inline-mock.gradle is incorrectly defined. It's currently defined as:

task copyMockMethodDispatcher {
    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')
            }
        }
    }
}

However:

  1. It's not defining any inputs! So the task doesn't know when to re-run.
  2. It's defining its output as "$buildDir/MockMethodDispatcher.raw", which is wrong, it should be in the /org/mockito/internal/creation/bytebuddy/inject directory...

The net result of this is that Gradle caches the fact the task has run and then even if the MockMethodDispatcher.raw output file is deleted, the task does NOT re-run.

It looks like this was done to avoid warnings under Gradle 7.x about tasks sharing output directories.

A better solution would be to move the renamed file to a new location, outside of the output of compileJava and include this in the jar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions