Idea deleting contents of Maven resource target directory

I have pretty straightforward Maven project I imported into Idea.  Project structure is:



Project Root

├───src
│   └───main
│       ├───java
│       └───resources

└───webcontent
    ├───css
    ├───images
    └───js

I have Maven copy and filter any .js files I have in src/main/resource into webcontent/js with this resources element:


<resource>
     <filtering>true</filtering>
     <directory>src/main/resources</directory>
     <targetPath>../../webcontent/js</targetPath>
     <includes>
          <include>*.js</include>
     </includes>
</resource>

I got a big surprise when I executed Project|Rebuild Project off the menu and found that Idea had deleted the contents of the webcontent/js directory before copying/filtering the .js files from src/main/resources (there are many other .js files in webcontent/js that are not put there by resource filtering).

I can understand why Idea thought it needed to do this (though this is not how Maven behaves outside of IJ).  My question is how did it figure out the webcontent/js folder was in effect a 'generated-sources' directory?  Also, what is really happening when I do a Build|Rebuild Project.  I would assume it is the exact equivalent of 'mvn clean' followed by 'mvn compile' but this is not true because Maven would not delete the contents of the directory.  Just wondering where Idea leaves off and Maven begins in the whole build process...?


Any insight is appreciated.


Thanks




3 comments
Comment actions Permalink

On rebuild IDEA clears target output directories including those which are used for copying filtered resources which IDE picks up from Maven pom. Then, when make is performed, IDEA copies resources again according rules specified in pom. If you don't want it to be cleared invoke Build | Make Project, then IDE will compile/copy only source/resource changes.

UPD: There is also a setting 'Clear Output Directory On Rebuild' under the Settings | Compiler tab. When disabled IDEA should not clear the directory on rebuild.

0
Comment actions Permalink

Thank you Andrey.  I suspected that was what was happening.

I guess I was surprised the IDE did not just invoke a Maven clean followed by a compile which again does not clear the filtered resources target directory.

Do you happen to know the mechanism the IDE uses to filter the resources?  Is the IDE actually reading the POM or is Maven being invoked?

I also saw the 'Clear Output Directory On Rebuild' but don't like that option as generally I do want the IDE to clear out .class files on a rebuild and this option prevents that from happening.

Thanks again.

0
Comment actions Permalink

Do you happen to know the mechanism the IDE uses to filter the resources?  Is the IDE actually reading the POM or is Maven being invoked?

If build invoked from IDEA, Maven is not triggered - IDE actually reads the pom and copies resources according to the rules.

0

Please sign in to leave a comment.