Which maven build lifecycle phase is executed by clicking the " load maven changes " in intelliJ (you know, the little m letter that pops up each time you change something in the pom).
Cheers!
Well, thats a tricky question.
IDEA get project model using maven components classes, during import it does not execute maven goals per se.
IDEA loads maven libraries, injects into maven process, and calls maven classes directly.
In short words, at first IDEA reads project model (using
org.apache.maven.model.io.ModelReader class, I don't know if exact lifecycle exists)
Then dependencies and plugins resolved (well, again using maven classes directly, but this could be mapped to dependency:resolve). You can look implementation at org.jetbrains.idea.maven.server.Maven3XServerEmbedder
To generate sources, phase which set in File | Settings | Build, Execution, Deployment | Build Tools | Maven | Importing |Phase to be used for folders update used
Frameworks detection/compiler settings/language level/artifacts configuration/etc, are not taken from maven execution at all. For such things IDEA read pom.xml files using own parser.
But what do to want to achieve? If you describe your issue and what do you want to get in result, I'll try to help you find a solution.
Not a complete answer but for illustration a screenshot from IJ 2020.2.4. Guessing from the text "Analyzing..." showing up when clicking the "m" IntelliJ performs a mvn dependency:analyze using Maven dependency plugin.
[]
Related
I had a NoClassDefFoundError problem with some test, launched from IntelliJ. In order to repair the situation, I had to make several changes in many poms of the project - adding new packages and excluding some old ones for to escape the overlapping of them. Also, I reapired the situation with different versions. But the situation did not improve. Again, some package, declared in pom, was not found where it should be.
I refreshed the maven repository by
mvn -e clean install -U
, as is advised in https://stackoverflow.com/a/9697970/715269 - so old and upvoted answer, that it surely looks as Santa.
The problem remained unchanged.
I output the maven map. It was correct and it contained all needed.
I looked at the list of the External Libraries of the project. It was the old uncorrected list of overlapping jars with same names and different versions, and without good packages I added just now, and well seen in maven tree output!
Already hapless,
I reimported packages in IntelliJ
by:
Ctrl+Shift+A, Reimport All Maven Projects.
Ho! The list of libraries got repaired. And the problem, mentioned in subj, disappeared.
The question is: How it could happen, that the same project has that very pom for everything, but gets packages differently being launched in maven and in IntelliJ?
I know about that feature "delegate IDE build to Maven". And I keep it turned off. But I am NOT talking about the different SW for building. Whether they are different or not, they should be up to the actual pom's. And whereas maven, if turned off from the automatic building won't know about changes in poms, IntelliJ KNOWS about them. It could have jars up to pom, or up to maven - it has sense, but it simply has some old rubbish. Was there some deep thought under that construction?
Every time you manually change the pom.xml file, including the dependencies you need to load these changes into IDE. IDE does it on Reload from Maven action. See also Import Maven dependencies.
Intellij doesn't use maven to bulid and run a project except you are delegating build and run action to maven:
Since, IDEA doen't really use maven to run and build, it uses the pom.xml to import the project structure and "tries" to build the project the same way was maven does.
Actually, there are quite a few differences between these to build processes.
Generating sources or filtering resources (don't know if this is still an issue) aren't done during building the project with Intellij IDEA.
In case you are using code generation you have to build the project via maven first and then - when all the resouces are filtered and additional sources are generated - you are able to run, debug aso. the project with Inellij IDEA.
That's an important thing to be aware of and that's the reason why maven and IntelliJ IDEA project structures might get out of sync.
You can enable the "Reload project after changes in build scripts" feature and select the Any changes checkbox to keep your project structure updated:
Why should you disable this feature anyway
If you are working on a build file (gradle or maven is not important) reloading the structure on any change can be very anoying. It's cpu intense, dependcies are fetched aso.
Therefore, I prefer to reload project structure only in case of an external change. This happens when pulling an updated version of the build file for example.
I would like to generate a diagram including all of a maven module's dependencies, for all scopes except test. I've been using IntelliJ IDEA 2016.1, which has a nice UI when selecting 'Show Dependencies' from a pom file. However, you can only select 1 scope, or all scopes. All scopes is very cluttered due to test-scoped dependencies like arquillian. I'd like to show compile+provided+runtime.
I'm assuming that IntellJ is using the maven dependency:tree plugin underneath, whose scope options are the same. Are there any other convenient ways to do this either within IntelliJ or through a maven plugin?
Maven Helper plugin has a nice visualization of dependencies.
I'm playing with maven plugins, specifically i'm trying to develop a custom maven plugin for eclipse. All goes well, it builds from console ... etc until:`
"Plugin execution not covered by lifecycle configuration"
appears. I research and find this:
http://wiki.eclipse.org/M2E_plugin_execution_not_covered;
obviously i do not want to ignore the plugin's execution, the execute instruction does not seem to work, as for the delegate to project configurator, i am not able to find
AbstractJavaProjectConfigurator.java.
I've searched in org.eclipse.jdt , core and source but there is no reference to what i am searching, best match i could find was here:
http://git.eclipse.org/c/m2e/m2e-core.git/tree/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt
All in one, what i want to achive is this: "Starting with m2e 1.1, maven plugin developers are able to provide lifecycle mapping metadata as part of the plugin itself." as stated in the first link i inserted. Any help would be greatly appreciated.
To simply bypass the mojo execution or telling m2e to simply execute your mojo via maven embedder you need the following:
a proper lifecycle mapping as explained in your link. Reference: https://github.com/php-maven/maven-php-plugin/blob/master/ide-plugins/eclipse/tags/2.0.3/org.phpmaven.eclipse.core/lifecycle-mapping-metadata.xml
However I put it in the root of the eclipse project to be able to debug it (finding those extra resources sometimes failes if you put them in src folders).
A build properties to embedd it into build: https://github.com/php-maven/maven-php-plugin/blob/master/ide-plugins/eclipse/tags/2.0.3/org.phpmaven.eclipse.core/build.properties
Activation via dependencies and extension:
Hope this helps. I was confused about the project configurator too. But the above example does not require any project configurator.
I understand that this is against maven best practices, but maybe my situation is one of the few exceptions from the rule - at least I'm stuck with thinking of alternatives :(
The environment is this:
we have a legacy application with proprietary technology based interfaces to the outside world
we want to use flash as the new frontend
based on the legacy interface we generate flash classes and package them in a flash swc to be used by the frontend developers
based on the legacy interface we generate java classes which bridge the flash service requests (coming via blazeds) to our legacy interface
to make it more difficult, we don't want to / can't use a pom on it's own for each interface as we have dozens of them (interfaces) and they would only differ in their artifactId. Instead I use a "generic" project structure which will get parameterized (by jenkins) for each build. The project will only be used in an fully automated environment.
First I've tried to put all these in one "simple" project, which works up to the point where the artifacts should get installed.
My current approach is a multimodule project structure inspired by maven reference chapter 13, which has some disadvantages on it's own:
GenericProject
|
+-- GenerateSources from legacy interface
| +-- pom.xml
|
+-- Java
| +-- pom.xml
|
+-- SWC
| +-- pom.xml
|
+-- pom.xml
This approach has the disadvantage, that I have references from "Java" & "SWC" to the internal structure of "GenerateSource" which is ugly but tolerable.
What really gets in my way is that I have to heavily tweak the install & the deploy plugins to get artifacts with the name & version of the legacy interface which triggered the whole process.
I got it running now, but it looks very brittle.
I considered splitting/duplicating the project in two simple projects:
GenerateSources & Java
GenerateSources & SWC
But this would only solve the minor annoyance with the cross-references.
As Aaron pointed out in his comment, I'm unclear in stating the problem.
After some more experiments this got a lot clearer to me:
Essentially I have two problems to solve
install/deploy two artifacts together
name the artifacts different than the project.artifactId
Any suggestions to make the whole process more maven-like?
Thanks in advance.
After some detours with the multimodule approach I came to the following pragmatic solution:
use the build-helper-plugin to attach a secondary artifact to be installed/deployed automaticly
two-phase build:
2.1 generate a pom.xml via sed which contains resolved project.artifactId & project.version
2.2 run the maven build
Although you theoretically can use expressions as project.artifactId & project.version, maven gives you a warning for this . . . for a good reason:
When you try to reference the produced artifacts, nexus will give you a "Failed to read artifact descriptor for . . ." error.
I suspect this is because in the stored pom in the repository the expressions are unresolved!
You should write a small Maven plugin that you attach to the generate-sources phase. See the maven-annotation-plugin for an example (main class).
That will include the generated sources in the output of the GenerateSource and you can consume those classes just by including the dependency in the other POMs. Note that you should create those files under target/, not in src/.
As for install/deploy: Those plugins get their names from the plugins which create artifacts. So there must be something wrong with how you set the property. In your case, that's the JAR plugin. The documentation has an example how to set the name of the default artifact.
Try using Maven overlays, it's used to share resources between multiple web applications.
http://maven.apache.org/plugins/maven-war-plugin/overlays.html
I have a huge multi-module project , which is being built using maven.
Most of them are core modules , which are used in other modules for various purposes.
But , 9 of 10 times, there is no change in the core modules and there is just some change in the depending modules.
Sometimes, there might be a small change in 1 core module of the many.
The issue is, I want maven to know, if the current build in target folder of the core modules is the latest accroding to the code, i.e no changes were made to the core for that.If thats the case, then I want maven to skip building that module during the maven phases.except the assembly plugin phase, which takes care of assembling all my modules at one place.
Is there a neat way to do this.I.e some maven plugin already taking care of stuff like this??
Some light on this will be great help.
Thanks,
Neeraj
May be you can use the maven incremental build plugin or use Hudson/Jenkins to do an incremtal build.
Just use Hudson - it will scan your source repository for changes and only run a build once that has occurred. It works well with Maven out of the box too.