How to specify excluded folders in Maven POM

Is there a way to configure a Maven POM so that when IDEA creates a new project from the POM (File -> New Project -> Import from Maven), it can detect which folders should be excluded?

This will make it much easier for new project members to simply create the new project from the POM without playing around inside the IDE to configure source and excluded directories.

1
12 comments

Hi, Justin,

In general all the source, test and excluded directories should be automatically detected and configured. This process relies on information from pom.xml files.

What directories are not configured or configured wrongly?

Thanks,
Anton Makeev

0
Avatar
Permanently deleted user

Hi Anton

Thanks for helping.
I know how to configure the sourceDirectory and testSourceDirectory and the resources and testResources directories, but I haven't found a way to specify which directories I want excluded.
I suppose it is because Maven excludes everything by default.

Maven will let you specify exclusions within a source directory. (I haven't tested how IDEA handles that.)
But as far as I can tell, it applies to files, not directories.

IDEA has the feature of setting a directory to be excluded. This is a very useful feature as it prevents IDEA from scanning that directory and all subdirectories, and helps with source control management as well as clearing what can be an otherwise cluttered directory structure.
I would like IDEA to be able to read an excluded folders list from the POM file somehow. But I cannot find a way (or even think of a way) to achieve this.

I am aware of a maven-idea-plugin that will generate IDEA project files and module files (http://maven.apache.org/plugins/maven-idea-plugin/).
It supports IntelliJ IDEA 4.x and 5.x. I haven't tested it with 7 or 8.
However, people would be required to run the Maven plugin before opening IDEA.
Instead, it would be better if IDEA could detect configuration while creating a new project from the POM.
It does this very well with source and test directories. It also detects the JDK version very well.
I am looking for a way to specify excluded folders so that IDEA will pick it up straight away.

If there is currently no way to achieve this, maybe JetBrains could develop a Maven plugin that would accept configuration information.

Any suggestions or ideas are welcome.

Thanks very much.

Justin

1

Justin.

What directories exactly you want do be excluded?
Where do you want IDEA to read this information from?

Thanks,
Anton Makeev

0
Avatar
Permanently deleted user

Which directories?
Well, in my case, I have a "build" directory and a "java-gen" directory and many other directories that I want to exclude.

I was hoping you would tell me a way of doing it.
But otherwise here is my suggestion:

- Develop a Maven plugin (eg. intellij-maven-plugin)
- Have configurable settings inside the plugin that allow the user to specify various IDEA project/module settings
- Inside IDEA, when you create new project from POM, it reads the pom and searches for the configuration information inside the intellij-maven-plugin and uses that to override or provide default behavior to the newly created IDEA project file and module files.

Here is an example usage:
It would create a project with one module called "Module 1". It defines one source directory (src/main/java), two test directories, and two excluded folders (build and java-gen).

]]>

]]>

]]>

com.jetbrains.maven.plugins intellij-maven-plugin Module 1 src/main/java src/test/java src/it/java build java-gen ]]>

</plugins>

</build>

</project>

As a first step, I would look at the existing maven-idea-plugin as a guide.
Maybe IDEA could detect the existence of the maven-idea-plugin and use that for its configuration advice.

Edited by: Justin Clareburt on Nov 6, 2008 11:36 PM

0

Justin,

Could you please attach your pom file? I want to take a look at your configuration and find why IDEA doesn't exclude folders automatically (as it should).

As for the plugin, please create a jira request.

Thanks,
Anton Makeev

0
Avatar
Permanently deleted user

Hi Anton

My POM file does not contain definitions for excluded directories because I haven't worked out how to specify them.

Are we on the same page? I am talking about the IDEA feature of an "excluded folder", which is specified in IDEA in the module settings in the same place that source and testSource folders are configured.
When you create a new project from a POM file, IDEA detects the source and test folders from the POM by reading various settings in the "build" section.
Is there a way that IDEA can pick up excluded folders from a POM file when creating a new project from the POM?

Are you able to provide an example of how I would configure a POM to exclude a directory called "foo"?

I figured there was no way to do this.
If there is a way, please show me.

Thanks

Justin

0

Justin,

IDEA automatically excludes the build 'target' folder, providing that there are no generated sources under it, otherwise it excludes all sub-folders but the generated.

If you have some generated code or build artifacts that you want being excluded, you may put it under the 'target' folder. There is no other way IDEA can detect what folders are to be excluded (at least at the moment). Your idea with custom plugin is quite interesting, though, I'll mull it over.

Thanks,
Anton Makeev

1
Avatar
Permanently deleted user

Thanks Anton

That clears things up for me.
In future, I will try to use the target directory for excluded folders.

In the meantime, it would be great if you would consider some options for pre-defining module settings.
That way, I won't have to check in my IDEA project/module files or new users to import, as they will be able to import settings directly from the POM.

Cheers

Justin

0
Avatar
Permanently deleted user

I'm finding this behavior frustrating. I should be in charge of which folders are sources, test-sources, and excluded not IDEA.

The way I'd like IDEA to work is to set up the iml for a project as best as possible when I first import a Maven project, currently it gets the java sources and resources correct but misses my groovy sources. From then on I'd like to be in control and have my configuration settings in IDEA stick.

Classic problem I've had for awhile now: Using the gmaven plugin to compile groovy files. Gmaven generates stubs into the target/generated-sources folder. I'd like to configure IDEA to ignore those stubs in favor of the actual groovy sources so I can run my unit tests, etc in IDEA. This issue has been around for awhile now but it seems that IDEA development is going toward a more restrictive, 'we know better', approach instead of a you-be-in-charge approach.

There is no way Intellij can predict the future of what plugins are made available for Maven. Right now gmaven won't work with IDEA but you can't just make an exception there, other scripting language plugins will probably also have this issue.

I guess the issue is a misconception on what the generated-sources folder is for. It is not just for generated J2EE files, or JAXB bindings, etc. It is also for code stub files for JVM scripting languages. If you include those stubs as 'sources' in IDEA then you get the duplicate source errors when you try to run a test using the built in compiler.

Please let us be in control. My next step is to try to make the iml's read-only to try to fool IDEA into letting me control my project.

1
Avatar
Permanently deleted user

My current workaround is to make sure I delete the generated sources folder after every maven build (inside IDEA or from the command line). This allows me to also compile with the IDEA built-in compiler and run unit tests, debug, etc within IDEA.

For my own sanity I created a small command-line script to do a maven 'install' then delete target/generated-sources.

Hopefully this workaround will help others

0
Avatar
Permanently deleted user

Although I understand your point I don't agree with you.

For my projects, I'm very happy that IDEA picks up sources/resources roots from an execution of the maven lifecycle (if I'm correct that's actually what's done).
In my case, I'm developping some tag libraries with a number of generated classes, and IDEA picks them up just right.

So what IDEA's doing is actually setting up your project as your maven project is setup, which makes sense.

Now, if IDEA was able to store any project setting modification on a maven-backed module as a "patch" and allow you to reapply it after reimporting, that would be great, and probably would solve your issue

0
Avatar
Permanently deleted user

I'm not in disagreement. I think it is great that IDEA does that when you first import a project but I'm not so pleased when it happens every time you compile. I've gone into the problem in detail so I won't rehash it but again it comes down to IDEA not giving you the power to completely ignore the 'target' folder. If you haven't tried to use a JVM scripting language plugin with maven (gmaven for groovy) then I don't think you'll understand the issue.

I've come up with another work around for now. I add this to my pom . Basically it simply deletes out the target/generated-sources folder after every maven install. org.apache.maven.plugins maven-antrun-plugin install run ]]>
<delete dir="$/target/generated-sources"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

0

Please sign in to leave a comment.