This message was deleted.
# kotlin-dsl
s
This message was deleted.
v
While the place is better now, you probably need to ask more concretely. What you wrote sounds like "please rewrite this for me" which you for sure did not mean šŸ™‚
v
oh yes... I have been working for 2 days on that šŸ˜‰ sorry. I’m struggling with this part
Copy code
configurations {
	asciidoctorExt 
}

dependencies {
	asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor:{project-version}' }
asciidoctor { 
	configurations 'asciidoctorExt'
}
my best try was something like this :
Copy code
val asciidoctorExt = configurations.create("asciidoctorExt")
dependencies {
	asciidoctorExt("org.springframework.restdocs:spring-restdocs-asciidoctor:3.0.0")
}
tasks.asciidoctor {
	configurations(asciidoctorExt)
}
v
And what's the catch with your best try? From a cursory look it looks fine, even though I personally would use
val asciidoctorExt by configurations.creating
v
oh now it compiles. and the build is ok... So I guess it’s all ok for gradle. but still it doesn’t generate the html file it is supposed to. it generates only the snippets. I guess that is another issue then.. thanks @Vampire . Your migrating link will be useful for sure. You did help.
šŸ‘Œ 1
@Vampire actually I have this error :
Copy code
Could not determine the dependencies of task ':asciidoctor'.
> Configuration with name '<path>/spring-restdocs-asciidoctor-3.0.0.jar' not found.
how could I resolve that ? I have tried to specify a version but it doesn’t work šŸ˜ž and I searched the web nothing. if you have another magical link i would gladly appreciate
v
That's not a configuration name. You somewhere configure a path where a configuration name is expected it seems.
v
thanks for taking the time. I don’t understand because it’s the configuration we did above.. here is my whole file build.gradle.kts
is there a way to see which line is wrong then ?
v
Some general notes: • Don't use the legacy
apply
• 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 Almiray
v
Oh thank you so much for taking the time. I'm so relieved it's not me... I will review all your details tomorrow first thing in the morning and correct my code. And try to open my first issue with asciidoctor. I will probably copy paste your remarks if you don't mind. Of course I will cite you and add the link here when it's done. I'm so happy you cleared it. 🫰
šŸ‘Œ 1
v
If you share a link to the conversation, use it from linen.dev, then it's not bound to the 90 days limit and also publicly accessible
v
Ohhh... ok I'll have a look tomorrow. But if you prefer to actually open the issue yourself please go ahead since you actually did find it and understand what is going on... Your call. I'm just so happy all the work and research I've been doing is not the reason for the issue..
Hello @Vampire, Thanks a lot for all you remarks and solution to my asciidoctor problem. I did my best to clean my build file according to your remarks and pushed it to my github. I Have a few questions regarding gradle though.. 1. ā€œ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ā€ - if I use the gradle bom as such
Copy code
dependencies {implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))}
then I have a
Copy code
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’) } }
thanks šŸ™
v
```> 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 ().configureEach
The
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 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/
Not 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.
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.
v
Thanks Vampire, - I’m afraid the BOM is also not working with
providedCompile(ā€œorg.springframework.boot:spring-boot-starter-tomcatā€)
- ().configureEach = explaination very clear thank you - kotlinDslAccessorsReport => I would have like something
Copy code
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 ? :
Copy code
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 link
Copy code
tasks.named<BootJar>("bootJar") {
	mainClass.set("com.example.ExampleApplication")
}
send an error :
Copy code
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 :)
Copy code
springBoot {
	mainClass.set("com.example.ExampleApplication")
}
v
I’m afraid the BOM is also not working with
providedCompile(ā€œorg.springframework.boot:spring-boot-starter-tomcatā€)
You got me wrong.
Copy code
providedCompile(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
instead of
Copy code
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
I would have like something
Copy code
gradle kotlinDslAccessorsReport clean
for example.
But what would that give? o_O Anyway no, there is nothing like that I'm aware of.
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 both
Well, 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.
v
Bom : oh sorry.. but I have another error
Copy code
Execution failed for task ā€˜:bootWar’.
> Could not resolve all files for configuration ā€˜:developmentOnly’.
   > Could not find org.springframework.boot:spring-boot-devtools:.
     Required by:
         project :
Copy code
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/678
v
Could 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 free
It 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 vscode
Well, 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. šŸ™‚
v
Ahahha šŸ˜… thanks a lot I have learnt a lot with you. Whenever I have time I will look back and search these answers. Next week I'll have to actually code now that the configuration is good enough. More problems are to come.... So hard to be a padawan...
šŸ‘Œ 1
Arf