# file

abstract fun file(path: Any): File(source)

Registers an output file.

For an absolute path, the location is registered as an output file of the TransformAction. The path is required to point to the InputArtifact or be inside it if the input artifact is a directory. Example:

    import org.gradle.api.artifacts.transform.TransformParameters;

    public abstract class MyTransform implements TransformAction<TransformParameters.None> {
        @InputArtifact
        public abstract Provider<FileSystemLocation> getInputArtifact();
        @Override
        public void transform(TransformOutputs outputs) {
            File input = getInputArtifact().get().getAsFile();
            if (input.isFile()) {
                outputs.file(input);
            } else {
                outputs.file(new File(input, "file-in-input-artifact.txt"));
            }
        }
    }

Content copied to clipboard

For a relative path, a location for the output file is provided by Gradle, so that the TransformAction can produce its outputs at that location. The parent directory of the provided location is created automatically when calling the method. Example:

    import org.gradle.api.artifacts.transform.TransformParameters;

    public abstract class MyTransform implements TransformAction<TransformParameters.None> {
        @InputArtifact
        public abstract Provider<FileSystemLocation> getInputArtifact();
        @Override
        public void transform(TransformOutputs outputs) {
            File myOutput = outputs.file("my-output.transformed");
            Files.write(myOutput.toPath(), "Generated text");
        }
    }

Content copied to clipboard

The registered file needs to exist when the transform method finishes.

#### Return

determined location of the output

#### Since

5.3

#### Parameters

path

path of the output file