Slackbot
07/19/2023, 7:12 AMVampire
07/19/2023, 7:19 AMopenApi
configuration? While you might get the path in-place with your setup and thus can use those tricks you used, I'm not sure this is always the case or in any way guaranteed.Jean Helou
07/19/2023, 7:22 AMVampire
07/19/2023, 7:27 AMJean Helou
07/19/2023, 7:29 AMJean Helou
07/19/2023, 7:30 AMinputSpec.set(provider { openApiConf.singleFile.path })
Jean Helou
07/19/2023, 7:30 AMJean Helou
07/19/2023, 7:31 AMJean Helou
07/19/2023, 7:34 AMVampire
07/19/2023, 7:35 AMVampire
07/19/2023, 7:36 AMJean Helou
07/19/2023, 7:36 AMJean Helou
07/19/2023, 7:37 AMAnother way could be to share the entrypoint in one configuration and the fragments in a second configuration, requiring to first combine them again on consumer side.wouldn't this require having 2 entries in the dependencies : one for each configuration ?
Vampire
07/19/2023, 7:37 AMJean Helou
07/19/2023, 7:38 AMJean Helou
07/19/2023, 7:39 AMJean Helou
07/19/2023, 7:39 AMJean Helou
07/19/2023, 7:39 AMOr to just have the entrypoint on top-level and all other files at least one directory deep.would help
Vampire
07/19/2023, 7:39 AMVampire
07/19/2023, 7:40 AMVampire
07/19/2023, 7:40 AMJean Helou
07/19/2023, 7:41 AMJean Helou
07/19/2023, 7:42 AMThe entry point will then be the only file on top levelhmm and I would add the directory to the configuration and inspect the directory content to find the entrypoint (it being the single file) and inspect the directory content again to find the fragment's directory I guess that could work
Vampire
07/19/2023, 7:44 AMJean Helou
07/19/2023, 7:45 AMopenApiGenerate {
// [... irrelevant openapi config ...]
// inputSpec.set("$projectDir/../api-contract/contract/spec.yaml")
// replaced by
inputSpec.set(provider { openApiConf.singleFile.path })
}
tasks.openApiGenerate {
// ensures the task depends on all open api fragments next to the contract (aka common.yaml and foo.yaml)
inputs.dir(file("$projectDir/../api-contract/contract/"))
}
one inspection in the openApiGenerate block's provider to get the entrypoint
one in the openApiGenerate task definition to add the inputsJean Helou
07/19/2023, 7:45 AMVampire
07/19/2023, 8:12 AMJean Helou
07/19/2023, 8:18 AMJust define the whole configuration as input files. No need to separate out only the fragments.I have literally no idea what this sentence means š I have published a repo with the full current solution at https://gitlab.com/jeantil/gradle-openapi-sharing the publisher project is https://gitlab.com/jeantil/gradle-openapi-sharing/-/blob/main/api-contract/build.gradle.kts the consumer projects are https://gitlab.com/jeantil/gradle-openapi-sharing/-/blob/main/api-client/build.gradle.kts and https://gitlab.com/jeantil/gradle-openapi-sharing/-/blob/main/api/build.gradle.kts to verify that things work as expected I run
./gradlew openApiGenerate
I expect that running this twice in a row results in 2 up 2 date tasks on the second run
I expect that changing anything in either the spec.yaml file or in any of the fragments results then running the comand again triggers a build
I have not yet started verifying the config cache behaviorVampire
07/19/2023, 8:20 AMinputs.files(openApiConf)
Jean Helou
07/19/2023, 9:17 AM.
āāā api
ā āāā build.gradle.kts
āāā api-client
ā āāā build.gradle.kts
āāā api-contract
ā āāā build.gradle.kts
ā āāā contract
ā āāā fragments
ā ā āāā common.yaml
ā ā āāā foo.yaml
ā āāā spec.yaml
āāā build.gradle.kts
āāā README.md
āāā settings.gradle.kts
(moved the fragment files to the fragments
directory)
I changed the producer build to
artifacts {
add("openApi", file(layout.projectDirectory.dir("contract")))
}
but my attempt at deriving the entrypoint
inputSpec.set(provider {
openApiConf.singleFile.listFiles()?.filter { it.isFile }?.first()?.path
})
fails
* Exception is:
org.gradle.internal.execution.WorkValidationException: A problem was found with the configuration of task ':api-client:openApiGenerate' (type 'GenerateTask').
- In plugin 'org.openapi.generator' type 'org.openapitools.generator.gradle.plugin.tasks.GenerateTask' property '$1' has unsupported value 'configuration ':api-client:openApiConf''.
Reason: Type 'DefaultConfiguration' cannot be converted to a directory.
Possible solutions:
1. Use a String or CharSequence path, for example 'src/main/java' or '/usr/include'.
2. Use a String or CharSequence URI, for example 'file:/usr/include'.
3. Use a File instance.
4. Use a Path instance.
5. Use a Directory instance.
6. Use a RegularFile instance.
7. Use a URI or URL instance.
8. Use a TextResource instance.
Jean Helou
07/19/2023, 9:17 AMVampire
07/19/2023, 11:04 AMinputs.dir
not inputs.files
Jean Helou
07/19/2023, 11:05 AMadd("openApi", file(layout.projectDirectory.dir("contract")))
should be
add("openApi", layout.projectDirectory.files("contract"))
?Vampire
07/19/2023, 11:06 AMVampire
07/19/2023, 11:06 AMVampire
07/19/2023, 11:06 AMVampire
07/19/2023, 11:06 AMinputs.dir...
instead of inputs.files...
like I showedJean Helou
07/19/2023, 11:06 AM//tasks.openApiGenerate {
// ensures the task depends on all open api fragments next to the contract
// inputs.dir(openApiConf)
//}
Vampire
07/19/2023, 11:07 AMJean Helou
07/19/2023, 11:08 AMJean Helou
07/19/2023, 11:09 AMinputSpec.set( provider {
openApiConf.singleFile.listFiles()?.filter { it.isFile }?.first()!!.path
})
}
tasks.openApiGenerate {
// ensures the task depends on all open api fragments next to the contract
inputs.files(openApiConf)
}
at least says it succeeds šJean Helou
07/19/2023, 11:09 AMJean Helou
07/19/2023, 11:09 AMVampire
07/19/2023, 11:10 AMJean Helou
07/19/2023, 11:10 AMJean Helou
07/19/2023, 11:10 AMVampire
07/19/2023, 11:11 AMinputs.dir(openApiConf).withPropertyName("openApiSpec")
, then the error should be better understandableVampire
07/19/2023, 11:11 AMVampire
07/19/2023, 11:12 AM--stacktrace
(or -s
) you should also see the exact line where the error happensJean Helou
07/19/2023, 11:17 AM* Exception is:
org.gradle.internal.execution.WorkValidationException: A problem was found with the configuration of task ':api-client:openApiGenerate' (type 'GenerateTask').
- In plugin 'org.openapi.generator' type 'org.openapitools.generator.gradle.plugin.tasks.GenerateTask' property '$1' has unsupported value 'configuration ':api-client:openApiConf''.
Reason: Type 'DefaultConfiguration' cannot be converted to a directory.
Possible solutions:
1. Use a String or CharSequence path, for example 'src/main/java' or '/usr/include'.
2. Use a String or CharSequence URI, for example 'file:/usr/include'.
3. Use a File instance.
4. Use a Path instance.
5. Use a Directory instance.
6. Use a RegularFile instance.
7. Use a URI or URL instance.
8. Use a TextResource instance.
For more information, please refer to <https://docs.gradle.org/8.2.1/userguide/validation_problems.html#unsupported_notation> in the Gradle documentation.
at org.gradle.internal.execution.WorkValidationException$BuilderWithSummary.build(WorkValidationException.java:133)
at org.gradle.internal.execution.WorkValidationException$BuilderWithSummary.get(WorkValidationException.java:115)
at org.gradle.internal.execution.steps.ValidateStep.throwValidationException(ValidateStep.java:162)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:86)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:49)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:71)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:45)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.executeWithNonEmptySources(SkipEmptyWorkStep.java:177)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:81)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:53)
at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:32)
at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:21)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:36)
at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:23)
at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:75)
at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:41)
at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:32)
at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:293)
at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:21)
at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:47)
at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:34)
at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:64)
is happens with gradle internals very early in the process
the withPropertyName tips is very useful thanks !!Jean Helou
07/19/2023, 11:17 AMVampire
07/19/2023, 11:19 AMJean Helou
07/19/2023, 11:21 AM