What's the “right” way to (temporarily) exclude sources from a maven build, and is there an easy way to do it from Eclipse?

前端 未结 2 1423
野的像风
野的像风 2021-01-19 21:19

I\'m new to maven, and I don\'t have a whole lot of experience with Eclipse either.

To exclude java files from building in Eclipse, I right click the files and choos

相关标签:
2条回答
  • 2021-01-19 22:04

    You could use the <excludes> parameter in Maven Compiler plugin to temporarily exclude files from compilation.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <excludes>
                        <exclude>**/model/*.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
    

    If you are using M2Eclipse plugin and run Maven->Update Project Configuration, the excluded files in the pom should automagically get excluded from eclipse compilation as well.

    0 讨论(0)
  • 2021-01-19 22:11

    if you choose maven as project management, then you really have to do it the "maven way".

    Eclipse builds the project based on the classpath specified in project properties and it doesn't relate to classpath of maven compiler plugin. "mvn compile" is driven only by configuration of compiler plugin.

    Usually these "temporary" changes are dealt with by JVM parameters appended to the maven goal (maven plugin/Mojo goal that you are running from cmd), that you create (custom one) and save in "Run as" > "Run configurations". I use commandline (shell) rather than m2eclipse for maven. changing parameters is quicker for me.

    To find out what parameters you can use, you can either specify the particular Mojo (maven plugin) in you maven dependencies (just temporarily) and look at its sources right in eclipse, you can see parameters that can be specified via "-D" JVM parameters. Or you can check the documentation.

    In compiler plugin there is a parameter private Set<String> excludes = new HashSet<String>(); but unfortunately collection parameters cannot be specified as JVM parameters... So the only option left is configure the plugin declaration in pom.xml.

    Then there are also profiles, but they are not useful for this case.

    To summarize it, your requirement is rather rare, excluding a java class from compilation is not a usual requirement.

    I hope it helps

    0 讨论(0)
提交回复
热议问题