Maven Lombok Annotation Processor and the Compiler plugin

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
ladies and gentlemen good evening I got this question about regarding maven and Lompoc how does it work and how should I configure the Mayman compiler so it actually includes the Lompoc and then also other frameworks I will not go into the other framework that was the question was quite the I was quite big there was also questions to other frameworks like something called map struct I will make a create another video with that let us first focus on how maven works and how how the how the annotation preprocessor works with the maila maven compiler plug-in and first of all I created this product right here by pressing file new and then project and this time I chose maven instead of usually I always choose Cato or or spring in each liza and then but this time i took i pressed maven and then i pressed then I looked for the archetype but if you're not used to if you're not used to maven then there is some archetype which is kind of the default template for how for creating an application and then as this one named QuickStart let me just go back here so if I press here somewhere wait from archetype then I can actually search for the one that is called QuickStart this is a good way to staff is a good one to start from then it just says that okay you have some code and you want to create a Java file that is actually what it says and then I press next when I came up with the name and on a person makes me finish and then I end up with this projects that I have right here here's the pump right here here's the pump file it said word source once one path servant to begin with I change this to 11 states um another thing was that don't know then I went and found the in project Lombok the dependency right here I'm gonna edit that you can find it on a product if it gives project Lombok that orc then you can find that the dependency right there and I got this j-unit already from the archetype so that is that was already there from out of the box so the next thing I did was I created a small data class right here named train and I added a field model and a float Max beat something like noaj constructor and all ice constructor and the data so that means it'll get get us and set us an equals method and yeah the hex code and I would get an ox constructor as a constructor without any arguments or give a constructor with old arguments that means all the fields I mentioned so I should get that automatically then I went to the app this class was created for me already I also chose the archetype QuickStart so then I got this class here then I and ER and I've got this line already hello world and then I added new train and then I gave in a crate a new train I'm not that good with train models yet I have to read up on a train models I just called name the city in 800 it probably exterminated or something like that but yeah that was the name that this one got and then of course in first first I went to until it here and then I saw that I could actually run this last right here run app and that works so I was happy but this isn't okay and so maybe maybe until you did something you're behind my back actually does because there's something called the lump clock in that I have installed and also enable for this protein right here so what doesn't also work now that we if we built it and yes it actually does first off when we are dealing with the Maven then we are dealing with life cycle stages and stages so we have a lot of life cycles right here clean validate compile chase bla bla bla bla bla then we had then I had a lot of plugins right here this is the plugins that I have added and here we have the we have the maven compile a plug-in that's actually what they does the medic here so let us try to build a sauce just try to clean install clean means that it deletes the target folder right there we just write them and install means that they will compile it compiler code and we'll create a file then it will install it into the local maven repository everybody has a default maven no local maven repository then also place the jar file in in that repository with the version that we have the sets somewhere and now it says build succeeds that is related goods so I go to my target folder and I can see I have a jar file right there there was actually one more thing I edit them just to that's I went down to the to the jar they plug in the job Luggin right here here's the job log in and then you need to add this configuration right here to say that this is the main class I also will not get a manifest file do not get the manifest file inside the gr5 so you need to say that this is the classes you want to run so that means that when people are running your Java file then this is the class that will be that it will actually be run so I also edit it after I did that then I could right-click then I can actually just press run inside and tell you run the Java file and I actually already did that so I have it up here and let me just show you a configuration that's nothing this is just default configuration and then I can press run like this run and then I get hello world and my train returned like that so it all works that is really really cool and but what how come it actually works because I have not I've not enabled any any notation and any pre annotation pre-compile or anything like that's how can how can I actually work that I just asked there I just add a dependency like that little unpacked dependency and then everything works out of the box I'm getting the annotations I'm getting you a new Java class created from all these families and invitations I'm adding there and we can also see if I go to my target and my class and I connected go look at my trained a class and I actually I can see here that I have my Garris I have my set us I have my equals method that this has been already now and where do we all get how come that I can get all this Matic here or it just by adding that dependency and that is because if it goes to the documentation for the Apache maven compiler plug-in then we can actually read that the a class pass the elements to supply as a notation processor path and be set here if it's not set then the compiler will detect annotation processors only in if it's a certain will be then comparable to take annotation process only in those class path elements if omitted and there and that is the case by default and the default class powerful Beach will be used to detect annotation processors and there are of course annotation processes that exact that's exactly what the may be part of Lompoc consists of course it needs to pretty need to process all the annotations that they are using and then it generates code out from that that means that the yeah the this plug-in here there's this cool Mayman compiler plug-in it finds the Lombok annotation processor and then it uses that and runs that's when we are compiling our code so it works automatically out of the box if you want to configure it you can just set the path just like this the one of the powerful questions it was long question powerful question I got was could you please show us how to configure it I'll say it go to this go to this page right here and then read how to set it up and I will yeah so this is how to set it up we can we can add compiled arguments and we can set the path if we don't want to if for some reason we do not want to just look for on a class path then we can actually just look in the path that we wish to look for it's pretty well documented so that is maven and so that is maven and the annotation preprocessor I would say another thing is that that I created if I create a springboard application steps our creators bring food application and stats and if I go to my humble XML file then it's pretty short and that is because in maven we can use something called a parent pump that means that we can actually inherit a functionality from a parent pump file and that is exactly what what spring uses a lot so I cannot see I cannot see any maven compiler in my pump file right now I had a I have a spray put maven plug-in right here that is blocking that spring made I have some dependencies right here and I also have my Lombok pendency right here and optional true that is actually a bit important or because we act we only needed one and either when we compile we do not need to add it to true the library itself I don't remember if I forgot to exits to set this to true in my my other project I'll go see in just a minute let's go check it out what did i do that's yeah we said scope provided in States and that it's exactly the same so Arsenal the true that means that the yeah we would you know we don't need it actually so it will we only need it when we compile occult we do not need it when we run the code itself but where is my maven compiler wise to plug in so maybe I want to configure right I cannot find it I cannot find it but if we go to the spring poot parent right there the artifact parent I just hold control and I click the parent right there then I end up in their parent pub and inside the parent pump if then you can go and look for maven compiler plug-in and then you can see is right here and then you can see how it is actually configured from spring by default you can all write this if you copy this part right here and if you added that who you are you add that to your own plugins here we have plugins and you can actually just alright it that's how it works so if you want this to be true or whatever also you want to add some more configuration right here you just do it like that and then then you are your version of the plug-in your configuration of it will be the one that's that that counts you should be it should you should be where you can actually break the spring the whole spring build process if you are if you're if you're playing too much with the plugins that spring rely on so if you can what definitely recommend you not to or write the plugins that spring normally use because it could give a problem that maybe doesn't give problem by now but in the upgrading and they're using some special configuration that that you've done or writes with your own plug-in configuration right here that's yes that's so that's actually I just want to show you that I also created a trained class right here with at data and I just want to show that I can actually if I go to Bayman then I can pretend I can write maven and then I can choose clean install if you choose minus X then you get a lot of extra information then it's like the - bumps info in greater and when we're dealing with quail then we are dealing with tasks instead of life cycles when we're dealing with I'm dealing with maven and this lifecycle send them is also something like that then we also do usually wood profiles because made one profile we just we want to do something special and then our profile with words want to do it something special while in cradle we do not use a profile in Quail itself so whether you prefer maven or Grail is it usually it's up to maven it's a little bit more a little bit more with huge lumps of it's just like putting big blocks together in the most in it I think it's usually more standard then it's more standard um with Gradle you usually end up with developers sitting and writing small scripts and creating variables to make everything work and maybe there was actually already a way that they could have this functionality work the way that the model - out of the box but then they did not read the documentation so they just created who's smaller variables and it may exclude some classes just because you can or something like that I think maven it's more it's usually clean up the made the combat XML file are usually cleaner but I'm a bit yeah the bit more verbose because it's XML of course then it's it's takes up some more space so whether you like you to be a craving a quail or maven that's yeah they're both good and they both to quit your building and producing the arts effects that we need out same so I like both the technologies but of course let me know in the comments if you have any preferences and and why but I think I answer the question all right the question asks something with the nothing with the Lombok and how does the notation preprocessor a processor wife when we are using the Lombok so we just add it to the class path and then because we're using the Mahler may even compile a plug-in then it would be used automatically in the compile phase just right here thank you very much for watching have a great evening hope to see you again soon bye bye
Info
Channel: Mike Møller Nielsen
Views: 4,286
Rating: undefined out of 5
Keywords: demo, tutorial, programming, java, lombok, maven, spring boot, spring framework
Id: sF0OgpjtmKk
Channel Id: undefined
Length: 13min 20sec (800 seconds)
Published: Mon May 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.