首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven-编译器-插件:每次执行更改<outputDirectory>

maven-编译器-插件:每次执行更改<outputDirectory>
EN

Stack Overflow用户
提问于 2017-01-05 11:10:26
回答 1查看 1.6K关注 0票数 1

情况

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

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

另一方面,数据库不支持Java8,因此为maven-jaxb2插件配置了第二个execution,以生成在不同文件夹中没有属性的源,最终在不同文件夹中的相同包中包含相同execution类的两个文件夹。

所以我现在看到的是:

代码语言:javascript
复制
 project
 \-target
   \-generated-sources
     +-java7
     | \-package.with.java.files
     |   \-Java7-compilabe-sources*
     \-java8
       \-package.with.java.files
         \-Java8-compilabe-sources*

接下来我要做的是将两个文件夹( target/generated-sources/java7target/generated-sources/java8 )编译到不同的输出文件夹中,target/java7/classestarget/java8/classes分别在不同的maven编译器插件执行过程中进行编译。

但我无法将maven编译器插件的输出目录更改为一次执行。

这是我当前maven编译器插件的配置。

代码语言:javascript
复制
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <verbose>true</verbose>
      <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输出来看,它似乎既不尊重<sourceDirectory>,也不尊重<outputDirectory>

代码语言:javascript
复制
[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文件),尽管<sourceDirectory>是在execution/config中提供的。
  • 编译器插件编译为target/classes,尽管<outputDirectory>是在execution/config中给出的

问题

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

附加信息

代码语言:javascript
复制
$ mvn --version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)
EN

回答 1

Stack Overflow用户

发布于 2017-01-05 15:13:55

我通过升级maven-antrun插件解决了这个问题。

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

代码语言:javascript
复制
    <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

代码语言:javascript
复制
    <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-antrun-plugin中配置了单独的执行,以编译eache源文件夹并创建单独的jars。

剩下的就是配置maven部署插件,以便将两个jars (以及它们的源jars)正确地放置在maven存储库中,以便将它们作为依赖项获取。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41483496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档