Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Task Not Executing Correctly #30244

Closed
oldvarion opened this issue Aug 20, 2024 · 5 comments
Closed

Dependency Task Not Executing Correctly #30244

oldvarion opened this issue Aug 20, 2024 · 5 comments
Labels
a:bug closed:unreproducible Unable to reproduce with given information

Comments

@oldvarion
Copy link

oldvarion commented Aug 20, 2024

Current Behavior

I'm facing an issue where a task intended to depend on another task's completion is not behaving as expected. The dependent task seems to run before the dependency is finished.

tasks.withType<RunWithPlugins> {
        val bootstrapDependencies = extension.bootstrapDependencies
        if (bootstrapDependencies.isEmpty()) {
            return@withType
        }

        pluginJars(provider {
            val jarFiles = bootstrapDependencies.flatMap { dependency ->
                val possibleNames = listOf(
                    ":${dependency.name}:${dependency.name}-paper",
                    ":${dependency.name}-paper",
                    ":${dependency.name}"
                )

                val targetProject = possibleNames.asSequence()
                    .mapNotNull { project.findProject(it) }
                    .firstOrNull() ?: throw GradleException("No valid project found for dependency ${dependency.name}")

                val filesProvider = provider {
                    val files = targetProject.layout.projectDirectory.dir("build/libs").asFileTree.files

                    var matchingFiles: List<File> = files.filter { file: File ->
                        file.nameWithoutExtension.contains(project.version.toString()) &&
                                file.nameWithoutExtension.contains("all")
                    }

                    if (matchingFiles.isEmpty()) {

                        dependsOn(targetProject.tasks.getByName("build"))

                        matchingFiles = files.filter { file: File ->
                            println("Processing file: ${file.name}")
                            file.nameWithoutExtension.contains(project.version.toString())
                        }
                    }

                    if (matchingFiles.isEmpty()) {
                        throw GradleException("Could not find any matching files for dependency ${dependency.name}")
                    }

                    matchingFiles.maxByOrNull { file: File -> file.readBytes().size } ?: throw GradleException("Failed to find the largest matching file for dependency ${dependency.name}")
                }

                listOf(filesProvider.get())
            }

            if (jarFiles.isEmpty()) {
                throw IllegalStateException("Could not resolve any dependencies in local project")
            }

            jarFiles
        })
    }

Expected Behavior

The dependent task should only start after the dependency task has successfully completed.

Context (optional)

No response

Steps to Reproduce

Create a Gradle project with two tasks: buildDependency and dependentTask.
Configure dependentTask to depend on buildDependency using dependsOn.
Execute dependentTask.

Gradle version

8.10

Build scan URL (optional)

No response

Your Environment (optional)

where? buildSrc script
where does RunWithPlugins belong? https://github.com/jpenilla/run-task

@ljacomet
Copy link
Member

We appreciate the effort, but we must ask for more information so that we can triage it.

We do not see an immediate root cause, and we need a minimal reproducible example for the triage. If we have a reproducer, we may be able also to suggest workarounds or ways to avoid the problem.

The ideal way to provide a reproducer is to leverage our reproducer template. You can also use Gradle Project Replicator to reproduce the structure of your project.

This issue will be closed after 7 days unless you provide more information.

@ljacomet ljacomet added the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label Aug 21, 2024
@oldvarion
Copy link
Author

  1. Create a script containing some task that already exists make it dependsOn("build") in buildSrc.
  2. Make a new module using that script and run the task and see if the "build" task which depend is on will execute

@oldvarion
Copy link
Author

  1. Create a script containing some task that already exists make it dependsOn("build") in buildSrc.
  2. Make a new module using that script and run the task and see if the "build" task which depend is on will execute

and also make sure that the task stuff is done in afterEvaluate block

@github-actions github-actions bot removed the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label Aug 21, 2024
@ghale
Copy link
Member

ghale commented Aug 22, 2024

Your instructions are a little unclear. It would be better if you provided a reproducer in the form of a project that demonstrates the behavior. Task dependencies are well tested in Gradle, so it's likely that if there is an issue here, it's due to a very specific set of circumstances.

@ghale ghale added the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label Aug 22, 2024
@github-actions github-actions bot added the pending:milestone Indicates that the completed issue requires a milestone label Aug 25, 2024
Copy link
Contributor

github-actions bot commented Sep 1, 2024

We previously asked for a reproducer, and unfortunately, none was provided. If you provide a valid reproducer, we may revisit this issue. In the meantime, this issue will be closed as unreproducible.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2024
@github-actions github-actions bot added closed:unreproducible Unable to reproduce with given information and removed to-triage pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days labels Sep 1, 2024
@ljacomet ljacomet removed the pending:milestone Indicates that the completed issue requires a milestone label Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug closed:unreproducible Unable to reproduce with given information
Projects
None yet
Development

No branches or pull requests

3 participants