Skip to content

Task dependencies are lost from accessTransformers.files.from(taskProvider) #318

@isXander

Description

@isXander

Problem

When doing something like

accessTransformers.files.from(aTask.flatMap { it.outputFile })

The implicit dependency to aTask is lost.

A problem was found with the configuration of task ':convertAccessxNeoforge' (type 'ConvertAccessxTask').
  - Gradle detected a problem with the following location: '/home/isxander/code/modstitch-toolkit-example/build/generated/accessx/neoforge/accesstransformer.cfg'.
    
    Reason: Task ':neoFormTransformSource' uses this output of task ':convertAccessxNeoforge' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

Code analysis (AI assisted)

The problem exists within two code paths: the source transformer and the binary transformer.

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/JavaSourceTransformer.java:102
common/src/main/java/net/neoforged/gradle/common/runtime/tasks/BinaryAccessTransformer.java:49

getTransformers().finalizeValueOnRead();

The problem here is finalizeValueOnRead(), which finalizes by resolivng the collection into concrete Files. For a provider-backed task output, that means the path survives, but the producer relationship can be lost.

DefaultConfigurableFileCollection.java

private void calculateFinalizedValue() {
    ImmutableList.Builder<FileCollectionInternal> builder = ImmutableList.builder();
    value.visitContents(child -> child.visitStructure(new FileCollectionStructureVisitor() {
        @Override
        public void visitCollection(Source source, Iterable<File> contents) {
            ImmutableSet<File> files = ImmutableSet.copyOf(contents);
            if (!files.isEmpty()) {
                builder.add(new FileCollectionAdapter(new ListBackedFileSet(files), taskDependencyFactory, patternSetFactory));
            }
        }

        @Override
        public void visitFileTree(File root, PatternSet patterns, FileTreeInternal fileTree) {
            builder.add(fileTree);
        }

        @Override
        public void visitFileTreeBackedByFile(File file, FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
            builder.add(fileTree);
        }
    }));
    setExplicitCollector(new ResolvedItemsCollector(builder.build()));
}

Solution

Switch to disallowChanges()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions