Slackbot
06/07/2023, 11:18 AMVampire
06/07/2023, 11:20 AMVampire
06/07/2023, 11:22 AMVirginie Fengarol
06/07/2023, 11:24 AMconfigurations {
asciidoctorExt
}
dependencies {
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor:{project-version}' }
asciidoctor {
configurations 'asciidoctorExt'
}
my best try was something like this :
val asciidoctorExt = configurations.create("asciidoctorExt")
dependencies {
asciidoctorExt("org.springframework.restdocs:spring-restdocs-asciidoctor:3.0.0")
}
tasks.asciidoctor {
configurations(asciidoctorExt)
}
Vampire
06/07/2023, 12:13 PMval asciidoctorExt by configurations.creating
Virginie Fengarol
06/07/2023, 1:11 PMVirginie Fengarol
06/08/2023, 10:08 AMCould not determine the dependencies of task ':asciidoctor'.
> Configuration with name '<path>/spring-restdocs-asciidoctor-3.0.0.jar' not found.
Virginie Fengarol
06/08/2023, 10:09 AMVampire
06/08/2023, 12:10 PMVirginie Fengarol
06/08/2023, 12:19 PMVirginie Fengarol
06/08/2023, 12:21 PMVampire
06/08/2023, 5:01 PMapply
⢠Don't use the Spring dependency management plugin, it is a relict from times when Gradle had no built-in BOM support and even its maintainer recommends not to use it anymore
⢠Don't use tasks.withType<...> { ... }
, that breaks task configuration avoidance, instead use tasks.withType<...>().configureEach { ... }
⢠{("asciidoctorExt")}
has not effect at all, just remove it; the point of using by
is that the name is taken from the variable name
⢠Use a task of type Delete
instead of an ad-hoc task and configure it instead of using doLast
as it properly declares which files it deletes
⢠Don't mix scopes, for example _asciidoctorj_ *{ ... }
configures the extension on the project, not on the task so having it inside the task configuration makes no sense*
But regarding your actual problem, that's imho a shortcoming of the Asciidoctor plugin that you should report.
There is configurations(Object... configs)
and configurations(Iterable<Object> configs)
and it can handle either Configuration
objects or anything else by converting it to a String
and using that as configuration name.
Configuration
is iterable, so the second variant is chosen. The configuration is iterated and so the File
instances are used.
On those then toString()
is called which gives the paths of the files in the configuration and that is then used as configuration name which gives the error you mentioned.
Before you gave a String
which is not Iterable
, so the first variant was used and interpreted as configuration name correctly.
So you either need to use configurations(asciidoctorExt as Any)
or configurations(_listOf_(asciidoctorExt))
or configurations(asciidoctorExt.name)
.
cc @ysb33r @Andres AlmirayVirginie Fengarol
06/08/2023, 5:38 PMVampire
06/08/2023, 5:43 PMVirginie Fengarol
06/08/2023, 6:14 PMVirginie Fengarol
06/09/2023, 2:11 PMdependencies {implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))}
then I have a
Execution failed for task ':bootWar'.
> Could not resolve all files for configuration ':providedRuntime'.
> Could not find org.springframework.boot:spring-boot-starter-tomcat:.
- I might stay with the ugly apply as recommanded by spring. But if you have an elegant solution, Iāll be happy to implement it. source
2. āDonāt use tasks.withType<...> { ... }, that breaks task configuration avoidance, instead use tasks.withType<...>().configureEach { ... }ā
Ok, so if I understand well : whenever I can, I use the type-safe model. If itās not available then tasks.withType<...>().configureEach { ... }.
but why ().configureEach ? I read the documentation but I didnāt understand this part.
3. Is there a command for the task kotlinDslAccessorsReport
to get it for just one task rather than all tasks? or is it better to go to : https://docs.gradle.org/current/dsl/
4. the custom task of type Delete has been hard to find.. Iām not sure my code is good. maybe I need to do a class, but I want to keep things very simple. It sounds to me I inversed the problem using must runAfter... you tell me.
5. Are these codes equivalent ?
// https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html#configuring-tasks
tasks.jar {
mainClass.set(ācom.vf.tickettothemoon_BackEnd.TickettothemoonBackEndApplicationā)
}
// mysolution from somewhere on the web
tasks.jar {
manifest.attributes[āMain-Classā] = ācom.vf.tickettothemoon_BackEnd.TickettothemoonBackEndApplicationā
}
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html#N2B1D4
tasks.jar{
manifest {
attributes(āMain-Classā: āpackage.Mainā)
}
}Virginie Fengarol
06/09/2023, 2:12 PMVampire
06/09/2023, 2:49 PM```> Could not resolve all files for configuration ':providedRuntime'.
> Could not find org.springframework.bootspring boot starter tomcat.```You use the BOM on
implementation
, but providedRuntime
do not inherit from implementation
so it of course has no effect.
I think if you instead use providedCompile
it may work, as implementation
and providedRuntime
both inherit from providedCompile
.
but why ().configureEachThe
tasks.withType<...> { ... }
exists longer than the task configuration avoidance APIs. It is a convenience method that then causes the tasks to be eagerly realized and configured, even if they are not going to be executed. The tasks.withType<...>().configureEach { ... }
on the other hand was added with the task configuration avoidance API to have a way to only realize and configure the tasks if they are actually needed by the current build execution.
3. Is there a command for the taskNot sure what you mean by "for one task". It tells you which accessors were generated because of the plugins that were applied. Hence the static DSL documentation you link to is a completely different thing. One is the DSL documentation of Gradle, the other lists you the generated type-safe accessors. But tbh I never used that task at all. If you use a proper IDE like IntelliJ, you can simply find by code-completion which accessors are available in a certain context. That is one of the big advantages of the Kotlin DSL.to get it for just one task rather than all tasks? or is it better to go to : https://docs.gradle.org/current/dsl/kotlinDslAccessorsReport
the custom task of type Delete has been hard to find.. Iām not sure my code is good.Not sure what you mean, your
clearAll
task looks good to me now.
Only the mustRunAfter
is questionable. Why must the clean
task run after your clearAll
task?
Or did you maybe intend to have a task dependency.
Like it is currently, you just define the order fo the two in case both are going to be executed.
And if you intended to have a dependency, so that clearAll
is run always when clean
is run, then a custom task does not make much sense anyway, unless you want to be able to run clearAll
without running clean
. If that is not the case, the clean
task already is a Delete
task so you can simply configure it to delete the additional files you want to have deleted instead of declaring a new task.
Are these codes equivalent ?I would say no,
mainClass
is not a property of the Jar
task, so the first version would most probably not even compile.
The second and third version should be the same from a cursory look, just that the third one is Groovy DSL, not Kotlin DSL.
But all three are most probably not what you want.
You probably intended to configure the mainClass
property on the bootJar
task, or on the springBoot
extension or on the application
extension if you would have the application
plugin applied, as documented at https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable.configuring.main-class
Spring Boot does not build a bad-practice fat jar where all dependencies are repackaged into your jar, but it is done "properly" by including the dependency jars as they are within your jar and using custom class loader to load the classes from them, so the jar build by Spring boot does not directly start your application class, but a wrapper that then properly sets up this custom class loader and then starts the real application.Virginie Fengarol
06/09/2023, 4:00 PMprovidedCompile(āorg.springframework.boot:spring-boot-starter-tomcatā)
- ().configureEach = explaination very clear thank you
- kotlinDslAccessorsReport => I would have like something gradle kotlinDslAccessorsReport clean
for example. I work on vscode thatās probably why :) thanks anyway
- clearAll task : intially I wanted the task to dependsOn(clean) but it doesnāt compile. Thatās why I added the mustRunAfter in the clean task because indeed I want clean to include the clear all task so I donāt have to do both.
FYI, as it is I can run clearAll separatly from clean.
āThe clean task already is a Delete task so you can simply configure it to delete the additional files you want to have deleted instead of declaring a new task.ā .Could you tell me how ? should I just do. Does it override clean or are the instruction add up ? :
kts
tasks.clean{
delete(ābinā)
delete (ā.classpathā)
delete (ā.gradleā)
delete (ā.nb-gradleā)
delete (ā.projectā)
delete (ā.settingsā)
delete (ā.vscodeā)
delete (ā.DS_Storeā)
delete (ā.ideaā)
}
- codes equivalent ? = oh, ok thanks š indeed I intended to configure the mainClass property on the bootJar task. I thought tasks.jar was the safe-type model of tasks.named<BootJar>(ābootJarā) {}.. thanks for the documentation linkVirginie Fengarol
06/09/2023, 4:17 PMtasks.named<BootJar>("bootJar") {
mainClass.set("com.example.ExampleApplication")
}
send an error :
Line 80: tasks.named<BootJar>("bootJar") {
^ Unresolved reference: BootJar
Line 80: tasks.named<BootJar>("bootJar") {
^ Type mismatch: inferred type is () -> ??? but Class<TypeVariable(S)!>! was expected
Line 81: mainClass.set("com.vf.tickettothemoon_BackEnd.TickettothemoonBackEndApplication")
^ Unresolved reference: mainClass
But its ok with so no worries :)
springBoot {
mainClass.set("com.example.ExampleApplication")
}
Vampire
06/09/2023, 4:32 PMIām afraid the BOM is also not working withYou got me wrong.providedCompile(āorg.springframework.boot:spring-boot-starter-tomcatā)
providedCompile(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
instead of
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
I would have like somethingBut what would that give? o_O Anyway no, there is nothing like that I'm aware of.Copy codefor example.gradle kotlinDslAccessorsReport clean
I work on vscode thatās probably why šWell yeah, that's the price you pay for using a fancy text editor instead of a real IDE š
dependsOn(clean) but it doesnāt compile
dependsOn(tasks.clean)
Thatās why I added the mustRunAfter in the clean task because indeed I want clean to include the clear all task so I donāt have to do bothWell, as I hopefully explained properly, this is not doing what you expect it to. š If you run
clean
it only runs clean
, if you run clearAll
it only runs clearAll
, if you run both you defined the order in which they have to run which does not make much sense in your case.
FYI, as it is I can run clearAll separatly from clean.Of course, as I explained. š
Does it override clean or are the instruction add up ?Depends on what you do, you can do either way. But like you showed it now, it does exactly what you want.
I thought tasks.jar was the safe-type model of tasks.named<BootJar>(ābootJarā) {}No,
tasks.jar
is tasks.named<Jar>("jar")
, tasks.bootJar
is tasks.named<BootJar>("bootJar")
.
Again, if you would use a proper IDE, you could just Ctrl+Click it and see what it does. š
send an error :Like in any programming language, you need to import the classes that you want to use. Kotlin and Groovy are not different. It is just that all the built-in standard stuff is imported automatically just like
java.lang.*
is in Java.
But BootJar
comes from the Spring Boot plugin, so you would need to import the BootJar
class.
Or just use the type-safe accessor tasks.bootJar
.
But generally I'd prefer configuring extensions instead of tasks where possible anyway.Virginie Fengarol
06/09/2023, 5:30 PMExecution failed for task ā:bootWarā.
> Could not resolve all files for configuration ā:developmentOnlyā.
> Could not find org.springframework.boot:spring-boot-devtools:.
Required by:
project :
gradle kotlinDslAccessorsReport clean
Of course I did try before asking and.. no
dependsOn(tasks.clean) works like a charm thanks. Now I understood all the diferences. I choose a separate task dependensOn (cause erasing the .vscode is painfull ;)
intellJ seems quite cool, but not free. iām still a student so... and I have invest in learning eclipse and vscode.. So Iām done for the moment. I need to learn how to code and do things with good practice first :D
import the BootJar class : hum were do I find the right import ? sorry Iām getting tired.. end of day here. and of this topic. :)
I have inform the community about the syntax problem on the social media :
https://asciidoctor.zulipchat.com/
https://app.gitter.im/#/room/#spring-projects_spring-restdocs:gitter.im
and they gave me the right repo address so ..
the issue is here : FYI https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/678Vampire
06/09/2023, 5:45 PMCould not resolve all files for configuration ā:developmentOnlyā.Well, maybe apply the bom to that configuration too then, or find out where in the hierarchy it is to find a better place? I don't use spring boot.
intellJ seems quite cool, but not freeIt is in the community edition if that is enough for what you need. And if it is not, it is always worth multiple times the 120⬠per year that it costs for the improved daily life you get even if you have to pay it yourself. š
iām still a student so...Then it is 0⬠for the all-products pack unless you want to use it commercially. And the GitHub students packages gives you another s***load of free stuff.
and I have invest in learning eclipse and vscodeWell, then come to the light side after trying pest and cholera. š If my employer would get the idea to force me to use Eclipse or VSC today, he would have my quit notice tomorrow latest. š
import the BootJar class : hum were do I find the right import ? sorry Iām getting tired.. end of day here. and of this topic. šYou could probably guess my answer. ;-) Either find it in the docs and manually copy it in if you use a text editor, or use a proper IDE that will make your life as developer much more enjoyable and easy. It would just give you the option to import the right class with a keypress or click. š
Virginie Fengarol
06/09/2023, 6:02 PMVirginie Fengarol
06/09/2023, 6:04 PM