当前位置: 首页 > 知识库问答 >
问题:

maven-compiler-plugin:每次执行更改

杨建章
2023-03-14

我需要在GUI(JavaXF)和oracle12c数据库中的JavaStoredProcedure中处理XML文件。

在GUI中,我想使用属性绑定。因此,我配置了maven-jaxb2-plugin来生成带有属性的源代码。

所以我现在拥有的是这样的:

 project
 \-target
   \-generated-sources
     +-java7
     | \-package.with.java.files
     |   \-Java7-compilabe-sources*
     \-java8
       \-package.with.java.files
         \-Java8-compilabe-sources*

接下来我要做的是在maven-compiler-plugin的不同执行中,将target/generated-sources/java7target/generated-sources/java8这两个文件夹分别编译到不同的输出文件夹target/java7/classestarget/java8/classes

但我无法为一次执行更改maven-compiler-plugin的输出目录。

这是maven-compiler-plugin的当前配置:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <verbose>true</verbose>
      <html" target="_blank">fork>true</fork>
      <encoding>ISO-8859-1</encoding>
    </configuration>
    <executions>
     <execution>
      <id>java8</id>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <executable>${jdk-1.8}/bin/javac</executable>
        <compilerVersion>1.8</compilerVersion>
        <sourceDirectory>${project.build.directory}/generated-sources/java8</sourceDirectory>
        <outputDirectory>${basedir}/target/java8/classes</outputDirectory>
      </configuration>
     </execution>
    </executions>
  </plugin>

但从maven输出来看,它似乎不尊重 :

[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 6.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MyProject ---
[INFO] Deleting /ProjectRoot/target
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.1:generate (Java8) @ MyProject ---
[INFO] Up-to-date check for source resources [[file:/ProjectRoot/src/main/xsd/parad.xsd, file:/ProjectRoot/src/main/xjb/bindings.xml, file:/ProjectRoot/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/ProjectRoot/target\generated-sources\java8\META-INF\sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.1:generate (Java7) @ MyProject ---
[INFO] Up-to-date check for source resources [[file:/ProjectRoot/src/main/xsd/parad.xsd, file:/ProjectRoot/src/main/xjb/bindings.xml, file:/ProjectRoot/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/ProjectRoot/target\generated-sources\java7\META-INF\sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MyProject ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MyProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 114 source files to /ProjectRoot/target\classes
  • 编译器插塞不显示执行ID(像maven-jaxb2-plugin那样)
  • 编译器插入编译target/generated-sources/java7target/generated-sources/java8(每个文件包含57个*.java文件),尽管 是在execution/config
  • 中给出的
  • 编译器插塞编译到目标/类尽管 是在execution/config
  • 中给出的

如何强制maven将target/generated-sources/java7target/generated-sources/java8分别编译到自己的目标文件夹?

$ mvn --version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)

共有1个答案

斜向文
2023-03-14

我通过使用maven-antrun-plugin解决了这个问题。

首先,我通过排除所有文件来结束编译:

    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <verbose>true</verbose>
      <fork>true</fork>
      <encoding>ISO-8859-1</encoding>
      <source>1.8</source>
      <target>1.8</target>
      <executable>${jdk-1.8}/bin/javac</executable>
      <compilerVersion>1.8</compilerVersion>
      <excludes>
        <exclude>**/*.*</exclude>
      </excludes>
    </configuration>

我还转向了maven-jar-plugin

    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
    <executions>
      <execution>
        <id>default-jar</id>
        <phase>never</phase>
        <configuration>
          <finalName>unwanted</finalName>
          <classifier>unwanted</classifier>
        </configuration>
      </execution>
    </executions>

剩下的是配置maven-deploy-plugin,以便将两个JAR(及其源JAR)正确地放置在maven存储库中,从而可以作为依赖项获取它们。

 类似资料:
  • 问题内容: 我正在尝试使用jaxb- maven插件使用JAXB将多个XSD转换为不同包中的POJO。我已将其设置为使用多个执行块,然后执行第一个执行块,然后出现一条消息:模式或绑定文件中未检测到更改 这是我pom.xml的摘录: 这是我收到的错误消息: 如果我交换执行块,则第一个总是执行,其余两个块得到相同的消息。 关于如何解决这个问题的任何想法? 问题答案: 通过升级到版本1.6进行了修复 和

  • 我正在学习Selenium,我想尝试将maven-compiler-plugin添加到pom.xml并重新导入maven设置。因此,我找到了这个例子来做它http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html,并尝试将代码添加到pom.xml。但是示例3.8

  • 我对Maven是新手。在Eclipse上,我在pom.xml中得到以下错误:- “在这一行找到了多个注释: pom.xml我得到错误:tag 注意:我能够在git Bash上成功构建。该错误仅显示在Eclipse中的pom.xml中。

  • 我在为父-子pom文件设置java编译器版本时遇到了问题。我在版本1.7的子pom中添加了maven-compiler-plugin,并注意到java版本的子模块从默认的1.5变成了1.7,而父项目仍然是1.5。然后,我将编译器插件从子pom移到父pom。预计对于父maven模块和子maven模块,编译器版本将更改为1.7。但奇怪的是,没有观察到任何变化,子模块仍然是1.7,父项目是1.5。我从e

  • [错误]无法执行项目SpringBoothelloWorld上的目标:无法解析项目Com.javainuse:SpringBoothelloWorld:jar:0.0.1-快照:无法解析以下项目:org.SpringFramework:Spring-Core:jar:5.0.10.release,org.xmlUnit:xmlUnit-Core:jar:2.5.1:无法传输项目org.Spring

  • 我正在尝试用Maven安装UIMA JDK。然而,总有一个警告 请帮助我解决此问题