Slackbot
08/09/2023, 10:16 AMTom Koptel
08/09/2023, 10:20 AM@get:OutputFile abstract val outArtifact: RegularFileProperty then I want to consume it as input in other place. I do set the outArtifact following way
outArtifact.set(layout.buildDirectory.file("native-config-plugin/configuration.json"))
What should I use for the consumer task?
Judging by docs it should be RELATIVE , though, I am not sure.
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val input: RegularFilePropertyTom Koptel
08/09/2023, 10:35 AMYes, you are correct. Thestrategy for the consumer task should bePathSensitivity.RELATIVE
The reason for this is that theproperty is set to a file that is relative to the build directory. When the consumer task consumes theoutArtifactproperty, it needs to know the relative path of the file, not the absolute path.input
If thestrategy for the consumer task wasPathSensitivity, then the consumer task would always use the absolute path of theABSOLUTEfile, even if the file was moved to a different location. This would make the consumer task brittle and less reusable.outArtifact
By usingGoogle Bard points out that, the consumer task will always use the relative path of thePathSensitivity.RELATIVEfile, which is more flexible and robust.outArtifact
RELATIVE is a correct value in this case.Tom Koptel
08/09/2023, 10:36 AMABSOLUTE strategy
Here are some examples when you might want to usefor theABSOLUTEstrategy:PathSensitivity
• When the file or directory is not relative to the build directory. For example, if the file or directory is located in the user’s home directory, you would want to useto ensure that the consumer task can always find the file or directory, no matter where the user’s home directory is located.ABSOLUTE
• When the file or directory is a symbolic link. Symbolic links are files that point to other files or directories. If you usefor theRELATIVEstrategy, Gradle will follow the symbolic link and use the path of the file or directory that the symbolic link points to. However, if you usePathSensitivityfor theABSOLUTEstrategy, Gradle will use the absolute path of the symbolic link, even if the symbolic link points to a different file or directory.PathSensitivity
• When you want to prevent the task’s outputs from being shared across different workspaces via the build cache. If you usefor theRELATIVEstrategy, Gradle will share the task’s outputs across different workspaces, even if the files or directories are located in different places. However, if you usePathSensitivityfor theABSOLUTEstrategy, Gradle will not share the task’s outputs, even if the files or directories are located in the same place.PathSensitivity
Tom Koptel
08/09/2023, 10:40 AMNAME_ONLY it shared the following examples:
• When you only care about the name of the file or directory, not the path. For example, if you are creating a task that copies a file, you might only care about the name of the file that you are copying, not the path to the file.
• When you are using a file or directory as a unique identifier. For example, if you are using a file or directory to store the configuration for a task, you might want to useto ensure that the task can always find the configuration file, no matter where it is located.NAME_ONLY
• When you want to prevent the task’s outputs from being shared across different workspaces via the build cache. If you useI can see that the 3-d statement conflicts with the 3-d statement aboutorRELATIVEfor theABSOLUTEstrategy, Gradle will share the task’s outputs across different workspaces, even if the files or directories are located in different places. However, if you usePathSensitivity, Gradle will not share the task’s outputs, even if the files or directories are located in the same place.NAME_ONLY
ABSOLUTE path usage. First it says that ABSOLUTE makes the file not shared by cache then mentions here that ABSOLUTE will make task output shareable to cache 🤦 So confusing 😞Tom Koptel
08/09/2023, 10:41 AMNONE
Here are some examples when you might want to usefor theNONEstrategy:PathSensitivity
• When you only care about the contents of the file or directory, not the path. For example, if you are creating a task that parses a configuration file, you might only care about the contents of the file, not the path to the file.
• When you are using a file or directory as a temporary file or directory. For example, if you are creating a task that generates a temporary file, you might want to useto ensure that the task always deletes the temporary file, even if the temporary file is moved to a different location.NONE
• When you want to prevent the task’s outputs from being shared across different workspaces via the build cache. If you use,RELATIVE, orABSOLUTEfor theNAME_ONLYstrategy, Gradle will share the task’s outputs across different workspaces, even if the files or directories are located in different places. However, if you usePathSensitivity, Gradle will not share the task’s outputs, even if the files or directories are located in the same place.NONE
It is important to note that usingfor theNONEstrategy can make your build less efficient, as Gradle will have to re-evaluate the inputs of the task every time it is executed. Therefore, you should only usePathSensitivitywhen it is absolutely necessary.NONE