Why does IDEA trigger a Maven build during a Maven project import?

Whenever I (re-)import a Maven project, IDEA (8.0.1) invokes (judging from the console output) "mvn generate-sources generate-resources generate-test-sources generate-test-resources". Apart from the fact that this is just equivalent to "mvn generate-test-resources", why does IDEA invoke this command in the first place? Why the need to compile the whole project (phase "compile" comes before phase "generate-test-sources")?

Cheers,
Peter

12 comments
Comment actions Permalink

+1

Our pom.xml actually includes some plugins that run as part of the
generate-sources phase. However - probably due to wrong class loading
assumptions - they crash when running as part of the IDEA pom.xml import.

Which makes me wonder, why does IDEA need to run generate-sources in the
first place, when I just want to synchronize the pom.xml dependencies to
the IDEA project configuration?

-tt

0
Comment actions Permalink

AFAIK the reason why this happens, is that for a number of projects (that the generate some sources obviously ) if you don't do that your project won't compile in the first place.
And especially because usually when you generate sources you do it different folders than the default ones, and add them to the maven reactor in the corresponding phases

0
Comment actions Permalink

File -> Settings -> Maven -> Importing -> "Automatically generate sources and update folders on import"

Turn that setting off and it won't run the generate * sources phases any more.

Seems like a design error to me.  An option to run only the generation phases that occur pre-compile may be more helpful.

Jeromy

0
Comment actions Permalink

as IDEA doesn't compile sources and test sources separately  they all happen before compile

0
Comment actions Permalink

Hi, Jeromy,

I'm not sure I understand you.
Could you explain this: "An option to run only the generation phases that occur pre-compile may be more helpful."?

Thanks,
Anton Makeev

0
Comment actions Permalink

Hi Anton,

As you know the default lifecyle includes:
...
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
genererate-test-sources etc

By pre-compile, I meant the phases that occur before the compile phase in the lifecycle.

It may be useful to have the option to:
  execute process-resources phase on import (so source is generated by no compile); or
  execute process-test-resources on import (so all source is generated but a compile is executed as per current option)

On further thought though, it may be more appropriate to simply allow the user to select a phase or mvn instruction to execute after import.  This would allow them to chose a profile or provide other options

regards,
Jeromy Evans

0
Comment actions Permalink

Jeromy,

Currently the main reason for running 'generate-resources' phase is to collect all custom source folders. If it was possible without execution the phase, it wouldn't be necessary at all.
There is a point in your suggestion, though; what would be a use case for this?

Thanks,
Anton Makeev

0
Comment actions Permalink

Understood.

There's two cases that are directly relevant to my projects.

The first, which is low priority, is that we use the maven-antlr-plugin in the generate-sources phase to generate java code that's required to build the application.  This use-case matches the current design; we need sources generated at import.  However, I wouldn't enable it because I can run the phase manually later in about 2 seconds rather than waiting for an unnecessary compile at import.  If I could instruct the plugin to invoke generate-sources only I would.  I can't imagine it being a much-used feature though.

More important to me, but out of the scope of this topic, is that the maven plugin will need to recognise the project's profiles at import. For example, for me a webapp executed within IntelliJ sometimes uses different webResources (directories) than the same webapp packaged for production use.  For instance, within intellij it's deployed with uncompressed javascript from src/main/js, but in the production profile it's deployed with compressed and concatenated javascript from a generated directory.  Right now I have to manually override the settings within IntelliJ for the web aspect, and on every manual import the settings are reset again. My initial thought was that running maven with different options at import (eg. -Pdevelopment) may help, but that's too late as the plugin has already derived the settings from the default profile.  In the future, it's likely to need to import based on a selected profile, or to recognise all available profiles and be able to switch between them. That's another topic and probably not a high priority either.

I can't think of any other valid case for running maven after import other than to execute the generate phases.

regards,
Jeromy Evans

0
Comment actions Permalink

I now understand why the compile goal is triggered, but I don't completely understand why compilation fails on import.  I've created a bug for this...

http://www.jetbrains.net/jira/browse/IDEA-20861

I've since disabled the generate sources option, so it's not the pain it was for me before.  However, I still think that the compilation step should pass without error.  From what I can tell, if it's a multimodule project where B depends on A, B will fail because it doesn't know how to get to A's classes (they haven't been installed or packaged).

0
Comment actions Permalink

The build that IDEA triggers on project import always gives me errors ("plugin not found" etc.), although our Maven build works fine. IDEA's Maven integration is a big pain for real word projects. I wish there was a "mvn idea:idea" for IDEA 8. That's really all I need.

Cheers,
Peter

0
Comment actions Permalink

This feature really slows down the initial import (and the maven sync) of any new project (and we have many small customer-specific projects).

I know that it's possible to disable it on a per project basis, but is it possible (or would it be possible in the future) to change the default behaviour? (To avoid having to change that setting for every new project.... especially since it will be done by default for the creation of a project from the main pom.xml)

0
Comment actions Permalink

Hi, Frederic,

We are working of this right now. In the last 8.1 eap you are able to choose a phase to run on the import. Be default it is process-resources and should not produce any compilation errors.

Thanks,
Anton Makeev

0

Please sign in to leave a comment.