5

我已经有工作的解决方案,我可以使用 maven 指定在使用特定 maven 配置文件时不编译哪些类。

但我想使用通用解决方案并改用注释

我目前的解决方案就像

<plugin>
    <!-- Exclude some web services used only for internal testing -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <optimize>true</optimize>
        <excludes>
            <exclude>**/something/*ClassPattern.java</exclude>
        </excludes>
        <testExcludes>
            <exclude>**/something/*ClassPatternTest.java</exclude>
        </testExcludes>
    </configuration>
</plugin>

但是有些东西像

@NotCompiledForProduction 

在课堂上会相当不错。

在我看来,如果不改变 Maven 的行为,这可能很难(或不可能做到)。这不是这里的范围。而这种注解

4

2 回答 2

1

您不能(我假设)使用注释来确定将哪些源代码呈现给 java 编译器,因为您首先需要编译源代码来处理注释。

似乎您需要在 maven 项目中创建不同的模块:一个生成带有生产代码的 jar 文件,一个生成带有测试实现的 jar 文件的模块,该文件依赖于生产工件。

如果代码确实需要在同一个 Maven 模块中,那么代码应该总是被编译。但是,您可以maven-jar-plugin在该阶段使用创建多个工件package:默认artifactId.jarartifactId-test-lib.jar工件。您可以通过为插件指定多个执行,并根据需要使用<includes><excludes>拆分 jar 文件来做到这一点。

于 2014-10-09T01:40:30.257 回答
0

你可以试试这个...

<build> <plugins>
  <!-- Run annotation processors on src/main/java sources -->
  <plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <executions>
      <execution>
        <id>process</id>
        <goals>
          <goal>process</goal>
        </goals>
        <phase>generate-sources</phase>
      </execution>
    </executions>
  </plugin>
  <!-- Disable annotation processors during normal compilation -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <compilerArgument>-proc:none</compilerArgument>
    </configuration>
  </plugin>
</plugins> </build>
于 2013-02-18T15:05:57.803 回答