简体   繁体   中英

Adding folders in maven project

let us say I have a standard maven project with the standard four Directories

src/main/java
src/main/resources
src/test/java
src/test/resources

Now let us suppose, I create a subdirectory named "clojure" under "src/main". Are then the source files under "src/main/clojure" automatically compiled when a build is run or do I somehow have to tell to maven, via configuration of some plugin (eg build-helper-maven-plugin), that it also has to compile the sources under "src/main/clojure"?

In others words, does the creation of any folder that is not ".../java" or ".../resources" require an explicit configuration in the pom.xml so that the sources there are taken into account by maven??

Any help would be appreciated.

Regards, Horace

A Maven project is usually built with a single compiler, which looks for all its source files in those folders known as source folders to Maven. Depending on the project, such source folders may be added automatically, eg src/main/java. If a different compiler is used, additional folders may automatically be added, eg src/main/groovy.

Sometimes Maven integrations in IDEs (like Eclipse or IntelliJ) do not pick up folders for non-Java projects, even though the correct Maven plugins are in the POM, say eg for building a Groovy project.

So even though a build on the command line may run nicely with files in src/main/groovy, the folder may not be detected as a source folder when importing the project in an IDE. In such cases you may have to add the additional source folders, eg

<plugin>
  <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
      <execution>
        <id>add-source</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>add-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>src/main/groovy</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

是的,maven需要“知道”这些目录的含义,尽管clojure构建插件可以按惯例使用该目录 - 例如:参见: https//github.com/talios/clojure-maven-plugin

Apache maven has a Standard Directory Layout which it understands out of the box.

To make maven understand any other structure than the above, you'll have to override these settings in pom.xml .

Look at this section of POM reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM