There's an IntelliJ command named exactly like my title: Generate Sources and Update Folders For All Projects. What does that do? I might have did a huge mistake by clicking on it before asking what that does. It's now running for more than half an hour. Wont stop and I'm too afraid to stop it.
What I wanted to do is switching to another GIT branch, but the workspace crapped itself and resulted in some build errors, so I thought I would click on everything that looks like a recycle icon. So I pressed this one on the maven panel: .
Does it do anything special? It clearly works much longer than an
mvn clean install -DskipTests
What anything other would I need? Actually until now I didn't even need anything other than that.
ps. (It has finished now, but I'm still curious what that functionality really is.)
The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.
The thing about generating sources is that its both a pre-build task (so that IntelliJ can access those generated sources for linting etc), and a build task (because these sources are not in source control and need to be generated with each build). So IntelliJ has this button to Generate sources and Update Folders while Maven has a generate-sources phase in its default lifecycle. They ALMOST do the same thing.
Whether sources have been generated or not, IntelliJ needs to know where to import from. You can set that here
File | Settings | Build, Execution, Deployment | Build Tools | Maven | Importing
When you build your project, Maven generates the sources, but IntelliJ still doesn't know that it should import them. That's why the button has two actions in one. Alternatively, you can right-click your target/generated-sources directory and select "Mark directory as > Generated sources root". It should turn blue. But using the button is better, since it will use any custom directories configured in your source-generating plugin (provided your imports are configured to "detect automatically").
The Generate Sources and Update Folders action doesn't appear in the Build Output or Event log, but it will show briefly in the Background Tasks window. If you want to see what it did, open your version of my ~/.cache/JetBrains/IdeaIE2021.1/log/idea.log file. IntelliJ appears to invoke the source-generating plugin directly (outside a lifecycle).
Note these open issues though:
Per the IntelliJ IDEA Maven FAQ:
In order to get generated sources automatically imported as source folders configure corresponding plugins so that they put them into target/generated-sources/, where subdir is any folder name you prefer. The subdir folder is necessary to distinguish sources from different tools and also to exclude some special generated sources (e.g. groovy stubs).
Please note that even if you manually configure some source folders under target/generated-sources of this folder itself, IDEA will rewrite them according to your pom.xml.
Any time you want to generate sources you simply execute the corresponding goal, bound for generation (usually generate-sources, generate-test-sources). After that IDEA will pick up new folders and set them up.
Per Maven docs:
Let's run though a short example to try and help. To generate sources you must first have a plugin that participates in the generate-sources phase like the ANTLR4 Maven Plugin.
So this is all fine and dandy, we have a plugin that wants to generate some sources from a Antlr4 grammar but how do we use it. You need to specify that you want to use it in your POM: If you then type mvn compile Maven will walk through the lifecycle and will eventually hit the generate-sources phase and see you have a plugin configured that wants to participate in that phase and the ANTLR4 Maven Plugin is executed with your given configuration. Furthermore during the compile you can observe that all the generated code (from your grammar files) will automatically being compiled without supplemental configuration.
As you can see Generate Sources action runs the generate-sources
Maven phase for any plug-ins in your pom.xml
that do generate any sources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With