【问题标题】:Exclude Java Source using Spring Boot Maven Plugin at Build time在构建时使用 Spring Boot Maven 插件排除 Java 源
【发布时间】:2017-11-09 16:24:03
【问题描述】:

我需要在运行 Maven 构建时排除某些 Java 源文件作为最终构建的一部分进行编译。

我在基于 Spring Boot 的项目中使用 Spring Boot Maven 插件。

我正在寻找一种将 Java 源文件排除在编译之外的方法,并且相应的 Junit 测试类也需要在构建时从最终构建中排除。

有没有办法使用 Spring Boot Maven 插件实现相同的功能?

【问题讨论】:

  • 如果我错了,有人纠正我,但这不是 src/test/java 目录树的用途吗?

标签: spring-boot toggle maven-compiler-plugin spring-boot-maven-plugin


【解决方案1】:

我通过配置 maven-compiler-plugin 实现了这一点:

pom.xml

  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>com/example/compileexclude/ExcludedJavaClass.java</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
  ...

作为参考,您可以查看所有可用的配置选项here

【讨论】:

    猜你喜欢
    • 2018-01-31
    • 2018-12-14
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2018-06-16
    • 2017-06-26
    • 2014-12-31
    • 1970-01-01
    相关资源
    最近更新 更多