Was Betteridge right?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello it's Duncan my video on gradal was my most popular yet and there was a lot of discussion on YouTube and Reddit but I don't want to be known for my rants my job as an engineer is to deliver value to my clients efficiently and effectively not to complain about how hard that can be that said Thank you to the people who said they were heartened by the knowledge that it isn't just them simple things are often harder than they should be thank you all people in jet R Who contacting me to discuss my issues both jet bra and gradel know there are problems with Bild tooling and both had talks at cing comp outlining their approaches neither have much detail but Amper is at least available in Early Access for us to try today's video doesn't do that though instead it starts from a new G clone of the project so that I can work out how to move from java 19 to 21 with a fresh pair of eyes and a fresh checkout oh good grief here we go in order to work out what went wrong and maybe learn from it I'm going to retrace my steps so here we are with the Kor documentation and we'll copy that URL okay then let's get clone that and now we'll open the directory in intellig so we will open we'll look in to delete Kor documentation and we'll go down into the code Snippets because that's the root of the gradal build where we have settings gradal kts so let's open that that and you can see here gradal is building configuring projects things happen we carry recording I have a cup of tea so now What's Happening Here I believe is that intellig is having to build with gradal which is to say execute the build files in order to know what projects there are and one of the reasons for that is if we look in settings. gr. kts for example which is the start of the build you can see here we add modules Snippets Jetty War Tomcat war and so on but we don't just declare them with project we have a function that is executed in order to declare them as projects well I say we this particular build does that and it does that to make this nice and neat and it also does it because down here it adds other projects depending on your operating system so making use of flexibility of a language to do things that we probably couldn't just declare if we had a declarative build system okay so now intellig has asked gradles to run some code gradles run the code and that means that intellig knows that there are these projects and I assume because we are Macos 10 then we will actually have a module which is client engine Darwin and let's have a look there we are we have client engine Darwin but we don't have client engine win or embedded server native okay then the next thing I'm going to do is go into the tutorial that I was interested in which is tutorial HTTP API so we'll drill down into that it's got source that creates two gradal modules one for Main and one for test so we're all doing well let's run all the tests in here and something happens okay and now we've got some output what do we have so cotlin JS gradal plugin is deprecated we bu in future well I guess this is a complicated project and it's designed to be multiplatform so that's okay more perent to be on the jvm is this here compile Java task current Target 19 and compile coton task current Target is 1.8 jvm Target compatibility should be set to the same Java version that would become an error it's gradal 8.0 which begs the question what version of gradal Are We running now that's sort of decided I think by the build up here so in gradal we have gradal rapid. properties and and that suggests at least that we're using gradal 7.6.4 in order to check that let's go to command line and we will run dog gradal wus minus version and that tallies gradal 7.6.4 what's interesting though as we saw last time is that the cotton inversion here is 1.7.10 and I believe though that that's not the version of cotlin that we'll be building with and it's not the version of cotlin we'll be targeting it's the version of cotlin that's used for pausing these kts files that are part of the gradal build and we also have a jvm version and again that's jvm 1.8 and that's the version that will be used for running this Gradle so Gradle is itself a Java application and so it needs to run on jvm and it will be running on 1.8 and the reason I think it's running on 1.8 is because on my Mac by default Java minus no not minus minus heaven for fend Min version is 1.8 something same version it is yes so gradal is a Java application that's running under the version of java it is current in the environment that we run it in okay back to when we actually ran a build that says here the current Target for Java is 19 now that's not necessarily the version of java that is going to be used to compile our project but it's the version of the bite code I think that we are going to be targeting so That Couldn't Run on jvm Whose version was less than 19 where does that come from well I had wondered whether it came from gradal properties because that includes a lot of versions including our cotlin version and our Kor version but it's not there let's try settings. gr. kts so that has no references to a version uh which I don't think is surprising because it's only supposed to be defining modules and finally bill. gradel notice this one's gradal and not kts let's have a look in here okay then this starts with a build script block and I think a lot of the complication here is around the fact that this project seems to be used to test different versions of things against different versions so there's this build snapshot train which makes everything a lot more complicated but carrying on down this I find completely hilarious this file is intentionally empty but we go on and we have a check and then for all projects we do some things ah X cotlin version is root project properties oh no this is only if build snapshot train so we can ignore that so nothing Kor repositories nothing Maven settings configure all projects some stuff around Maven but I don't think it's significant again if build snapshot train not interested carry on so nothing again about Java 19 in any of this that I can see and it's a shame that we can't see 19 anywhere because if you remember before we started beating off the alligators what we actually wanted to do was update the Java we were targeting to Java 21 maybe the 19 is specified somewhere else let's have a look in the whole project so we'll look for 19 and the 103 matches log for J version no something random in an ID 4.19 for package lock indexes manifests something in an SVG file but nothing specifies 19 in anything that seems to approach a Java version so that's no good but we do have this build.gradle kts in the directory for this particular subm module and that has cotland jvm but doesn't mention Java anywhere just check I mean in the whole project we barely mention Java nothing in any of these project files certainly so forc to assume that the cotlin jvm plug-in is the thing that brings in Java but then it's rather strange if it brings in a version of java and sets 19 and 1.8 to being incompatible with each other but okay I think I'm going to have to assume that the version of java we're using this this 19 is as a result of this cotlin jvm one thing I just like to look at is if we go here and say look at the settings for the project we are using 19 which agrees with what gradal appears to be setting and we have settings for our individual modules as well dependencies 19 so that all seems plausible except we don't know where 19 comes from one thing I would just like to do is to check that we are using the same gradal in both places if you remember here we did gradal minus minus version let's try and make a build configuration like that so I'm going to go up here and I'm going to say edit configurations I'm going to say give me a new gradal configuration and I want you to run minus minus version and let's run that and unknown command line version minus minus version that is strange let's go back here I'm going to edit the one I've got which I know works so here this says for example build minus minus debug and minus minus debug is certainly a flag so let's just try minus minus version here run that and the same thing so minus minus version appears to be a special command line option that is only visible when you actually run from the command line I don't know okay moving on just going to remove that if it's not going to help us and run good and now we haven't got the complaint about the versions but I assume that's because we haven't really cleaned so we haven't built so if I was to go here and say clean that's slower than you might like and fails oh good grief here we go compatibility gry I don't know Java 11 so in fact on the command line it turns out we could build but we couldn't clean is no actually we didn't try to build on command line did we let's do that so let's say/ gradal W uh where were we we were in Snippets colon colon tutorial hyphen HTTP hyphen API and that will invoke the default Target but seems to have the same problem okay and if I do the thing that I would normally do which is CD into Snippets tutorial HTTP and then dot do do dotg gradal W clean say I can't do that can and I do that via intell so I'm going to go to tutorial HTTP API say tasks build ah there we are clean is inside that so let's run that one and that does build so there something different in the way that intellig is running gradal and the command line is running gradal but I don't know what it is and I have no idea how to debug it bear in mind this is a clean checkout from GitHub not my build at all so now enough with the problem whether to just continue running gradal through intellig which seems to work or to try and get it running on the command line and because everyone would just say upgrade Gradle I think I'm just going to upgrade gradal and see where that fixes everything so same instructions as last time gradal wrapper la la la la la take that and now trust I'm going to be run enough of that on the command line let's give it a go so we'll say CD back to where we were and oh big CD little CD back to where we were and now paste that oh but for me twice shame on me dogrel W rapper upgrade some things happened and the build failed oh marvelous the same issue I mean know what I'm supposed to do now looking through the error it seems to be something about some Plug-In or something but nothing I'm actually using which I suppose is why this worked last time because I had deleted all the other projects I had to get myself back on an even ke here well actually I don't care about any of the other projects so hang it all I'm just going to delete them here we go so that one that one that one that one that one that one one moment please okay let's delete these refactor uh okay I can't delete I could remove each individual module oh I don't know I'm off the finder and delete them there okay here we go wish me luck now back to intellig okay we had a little crash there so now I'm going to run just that test again see how we are doing all of the great old demons would have gone so that will take a while okay so we're back to our issue with current Target 19 and compile cotlin task 1.8 but now let's go and try and upgrade gradal to fix that problem so we're going to do the thing that we tried to do before Splendid and run our build again running the tests and now I think behind the scenes we're probably downloading the new version of Gradle so this will take a while talk about yourselves okay and we are not seeing the error but on the other hand we didn't clean first so let's go over here and do that there okay and now in fact let's just run test here because we can idle oh here we go still building thing ah but fails there failing tests try running here passing tests uh back here just do the clean back here just run the test but we seem now to have lost our warnings that we were targeting a different version of java than we were targeting with the cotlin jvm plug-in okay one little thing I want to check I remember from last time is if I go to the settings and say build so gradal here so we we are build and run using gradal gradal and we are running the gradal with the wrapper and with the gradal gvm as the project SDK which I suspect is different than the one that grad on the command line is running maybe that's the issue uh interesting well I choose not to solve that problem just yet but I wonder whether it is a gotcha in fact hang it now let's go back here say gradal minus minus version to see that we are running Java 1.8 so now let's go back to here and say let's try running this with Java 1.8 okay and now will that have changed this task or not let's delete it anyway so let's delete that one and delete that one and now we're going to go over here and we're going to rerun The Source test tests see if they're failing the same way as command line does ah they do so I suspect that that is our issue running on the command line not certain but last time we did solve that problem by creating a new file in here with Java iph version and then inside that we're going to say I want to be running with 19.0 I think save that go back to the command line now run gradal and see what grad's running with and now it's running with 19 so I wonder whether that means in fact that gradal could run the tests we said CD into Snippets tutorial HB API and then say dot dot SL do do SL gradal W clean test okay so our test weren't able to run under 1.8 but by forcing Java to 1.9 we can run the test on the command line and now we should go back here and we should say that here I want to run not with 1.8 but with 19 okay and now that will work it will good we're making a bit of progress okay then so now we're going to do the thing that we did last time which is go to the bill. gr kts configure the cotlin plug-in and tell it that we want jvm tool chain 21 okay now let's try the build and as it builds on the Comm line as well I think we'll go straight there so that's talking to various jdks because we run up whatever tool chain is and now we have build failure and unknown cot jvm Target 21 hooray we're back to where we were two weeks ago but only one episode ago well 1.1 episode ago now then what I've learned since last week is that this exception here unknown cotton jvm Target 21 is because of a cotton inversion issue but the coton inversion issue is subtle so let's take that out the way a bit it turns out that this build the one for Kor code Snippets has a top level build.gradle and in the top level build. Gradle let's put that away in the build script block here we have a dependency with a class path of the or jet brains cotlin cotlin gradal plug-in with cotlin version now what does that mean well the cotlin Gradle plugin which is the thing that builds cotlin inside gradal is itself written in cotlin and is shipped as a jar and this is explicitly putting a particular version of that jar into the dependencies of the build script itself so it's not the version of cotlin We're going to be building with and it's not the version of cotlin that we're going to be targeting it is I think the version of cotlin that was around when the cotland gradal plug-in was written so I wonder in fact whether just commenting this out would get us running so that we use whatever the latest version is let's get that a go um no why oh well because it turns out we are not bringing in the gradal coton end plugin aha so putting this on the class path means that the plugin is available but I wonder then whether actually no I don't know my life is too short let's cut to the chase this coton inversion here is setting this gradal properties yes and is 1.9.10 but that didn't know anything about Java 21 so it couldn't Target it we upgrade this to say 20 and come back here and then reinstate this I believe things will be good holds breath and they are now you might say why is best this version at all and I think that's a good question if we just took this out all together I think it would use the latest one and we could run uh no it turns out not so there goes my logic let's redo that so we need a version in there it seems unless we find another way of getting this to compile without that bit so we go back here and run that what ever this error message is which is to say plugin ID or jet brains cotlin jvm was not found I thought that should happen because we doing this cotton in jvm um gradal core plugins included plugins included builds plug-in repositories ah plug-in dependency must include a version number for this Source was that the same thing as we were getting I don't know I think I'm just going to look up plugin repositories and see whether that helps oh no hold on it says try oh no we know that that's useless in fact let's just look up this error message and see what AI system has to say how do I fix this error okay so it's not my internet connection I suspect it's not my dral plug-in version I suspect the issue here is this plug-in Management in settings. gr. kts so this is our uh settings ofr kts it doesn't have does it it has a plug-in management and it says Gradle plugin and mve in central um so I just don't know so I would expect it to be able to find that now but it can't maybe it can't because it has to match the version number i' don't know what I do know is that I spent quite a bit of time on this and we do have a solution that works which is just upgrade the cotland version in here to a version of cotlin that admitted that Java 21 existed so if we look at our diffs we've changed this bill. gradal show diff so we've told cotland that we want to be building with 21 well that stopped things working so we need to put it back in so there are no changes to that and all we've actually really changed is the cotlin version to 1.9.2 which is a version that emits that Java 21 exists Splendid so just to recap the versions going on here gradal has a version and it has a built-in version of cotlin that it's using to pass kts files for its own build and and it has a version of the jvm that it is being run on cotlin inside our application is built by a cotlin jvm plug-in which itself is compiled against a version of cotlin but we'll be running on the jvm that grad itself is running on it will be targeting a version of java bite code through this jvm tool chain and I suppose actually a version of cotlin that's separate from its own version or the version that gradal is using with some version of cottin that we could put into here oh and then no doubt if we run the application through gradal or run the tests through gradal there will be a particular version of the jvm and a particular version of cotlin that do those two things and I'm sure configurable somewhere so how do we fix this does this need fixing well had some interesting discussions of cot and comp one was with Martin Brawn who is the Evangelist for Amper which is a building project configuration tool from jet brains it takes a declarative approach but as we've seen everyone's builds are different at some point we all want to be able to run code like this with any our builds and it's not all clear to me how that fits with the declarative tool Amper is both a wrapper on top of gradel and now has it own non-g gradal engine its tooling support seems good but where it is based on gradal all we're doing is layering Simplicity on top of complexity and if it decides not to be gravas on gradel then it pretty much has to reimplement everything that gradel can possibly do gradel isn't letting the grass grow under its feet it had a session on developer first gradel bills and again talks about declarative build principles and expressive dsls talking to the team this expressive DSL seems to be a subset of cotlin is effectively just the Builder DSL that configures plugins which will win out gradal or Amper or gradal and Amper who knows I think the only conclusion I've really come to is that it's all pretty awful at the moment most people agree that it must be made better and all I ever really needed to do was notice that this was set to an early version of cotlin and anyway thanks to everyone who commented on the previous video and on the post on Reddit thank you especially to Frank who was the first person to actually give a solution I promise now to shut up about gradal so hady doesn't have to send the boys around and we'll resume normal service looking at the throughput of HTTP 4K and Kor in the next episode if you'd like to see that then please subscribe to the channel and if you'd like to support my rants then you could buy the book that I wrote in that price called jav to cotlin refactoring guide book details of which are in the show Nots below thanks for watching
Info
Channel: Refactoring to Kotlin
Views: 752
Rating: undefined out of 5
Keywords:
Id: MP18mcCu8Hg
Channel Id: undefined
Length: 25min 30sec (1530 seconds)
Published: Fri May 31 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.