I am an Eclipse user who is trying out IntelliJ IDEA. When importing a maven project, in the wizard, I am asked to "Select profile". What aspects of the project is decided on this selection?
It lets you activate different profiles that are found in your pom.xml. The docs shown above give good information but not really how you would use a profile. For example, you may have a ''dev' profile for building in your dev environment or a ''production' profile for building when you are ready to deploy. Maven allows you to use a profile by using its 'P' flag after your build command, followed by the actual profile. Eg.
mvn clean install -Pdev
Hope this helps!
I usually don't select any profiles when I import a maven project for the first time.
Once you have imported it, you can later come back and tick any profiles you want to enable / disable prior to executing a build step (like clean install).
This seems the most straight forward approach to me.
It affects the way projects are imported
See doc : profiles
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 know there are 2 methode to create project with Maven.
Create Dynamic project on eclipse and convert it into maven project
Create Maven project with command line and then import the project into eclips.
i always do the 1. choise.
If You have latest eclipse IDE then its very simple.
Go to Create new Project wizard and search maven project. (if its old eclipse IDE then you probably need to install m2e plug in from market place).
select maven project and next. Check (Create a simple project) if you want customization other wise just click Next and You will be presented a number of ready made archtypes.
For simple console projects you can chose maven-archtype-quickstart. or what ever project you want to create.
Now Give groupId e.g. com.yourcompany or com.yourprojectgroup and artifactId e.g. projectname-alias . and Click Finish.
First Time eclipse will create local repo if its not already created and then put default dependencies defined by provided pom in your local repo. Further you just need maven knowledge to customize project. e.g. New Dependencies and build system etc.
I hope this will clear your mind. I prefer this way because its fast and easy.
If you create a new project in Eclipse (at least in Mars or Neon), you can choose "Maven Project" and get everything you need. Don't use eclipse goals of Maven. They are deprecated.
I thought maven was a way to build a project without relying on your IDE. I've been following instructions that involve my IDE only to find the project only works from within the IDE.
I happen to be using intellij but I wish I didn't even have to tell you that. Am I wrong or is there a way to build a maven project using keystrokes not "click this, then that" mouse instructions that change lord knows what in the IDE. A way that will work within an IDE but not be dependent on that IDE?
I'm hoping I have been following some instructions that simply didn't have this as a goal. Is there a way to build a maven project that will work just as well in intellij as eclipse? If so how do I find it? Is there a keyword I need to know to search for?
I'm probably misunderstanding something but I hope I've made my goal of having my project only depend on maven itself clear.
You can build a maven project from its directory using -
mvn clean install
Of course this requires Maven installed on the machine you are running it from.
Please look further into the documentation here as well.
I am new to IntelliJ but coming from Eclipse I expected Maven support to be far better. It really is but I could not find how to define a remote archetype catalog in IntelliJ (14.1).
All I could find was a way to add a Archetype manually but that is not what I need. I would like to point to a XML file on a remote server that contains the list of all archetypes available.
In Eclipse, it looks like this :
Maybe you would like to try an Intellij Plugin that I wrote yesterday. It enables you to add remote archetype catalogs to Idea: Maven Archetype Catalog plugin
To make my answer more clear: I had the same issue that it struggles me that you can add Maven Archetype Catalog files in Eclipse, but not in IntelliJ IDEA. So I tried to write a plugin for IntelliJ IDEA, so that you can actually define URLs to archetype-catalog.xml.
The plugin just parses those URLs and provides the Maven Archetypes to the list of available Archetypes in IntelliJ IDEA.
After installing the Plugin you can find a new entry in the Settings menu at File - Settings - Build, Execution and Deployment - Build tools.
I know this is kinda old thread, but in the future if some one will look for it.
This Maven Archetype Catalogs is a plugin for intellij that allows import external archetypes from a URL.
It solved my problem on Linux, haven't tried it on Windows.
To add this plugin go to File->Settings->Plugins->Browse repositories
in the search bar type "Maven Archetype Catalogs". Install and restart.
To use it go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven Archetype Catalogs. click the '+' and add the archetype-catalog
It seems that there is a plugin to do this - Maven Archetypes. The reviews are not favourable, and I have never used it though so cannot comment to its effectiveness.
You could also (assuming Windows/IntelliJ 14), edit C:\Users\<username>\.IntelliJIdea14\system\Maven\Indices\UserArchetypes.xml and add the archetypes manually. Not ideal, but still workable.
Screenshots are made in IDEA 14, I've also checked IDEA 13, it's also true for it.
If this is what you need
Then it's in the Preferences:
You can set several properties and configuration options in a Maven build within IntelliJ, but I haven't quite figured if you are able to specify options that are available on the command line such as --also-make or --also-make-dependents.
Is there a way to have those options used by Maven run configurations in Intellij?
You can create a run/debug configuration by right-clicking any goal in the Maven Projects view, select Create your-project[your-goal] and from there you can add any command-line parameters (such as --also-make). Your configuration will be saved and accessible from a single click on the green arrow :).
You can put --also-make into the per-project .mvn/maven.config file which sets command-line options to always apply.
In combination with IntelliJ's option to "Delegate IDE build/run actions to Maven" (which seems to be default when importing Maven projects these days), this gets building and running with the IDE's main buttons and menu items working. No more failures to resolve inter-module dependencies or failing Enforcer.
There may be undesirable side effects to always including --also-make but so far I haven't encountered them—in a multi-module project using the Reactor this way is just about always what I want, so it saves typing on the CLI too.
Side note: I still find #Bastien Jansen's answer useful for invoking other run-like Maven goals, like spring-boot:run with IDEA Community Edition which does not have the more first-class support for Spring Boot applications that Ultimate does.