【问题标题】:In maven, add a folder as a source folder but dont include it in source jar在 Maven 中,添加一个文件夹作为源文件夹,但不要将其包含在源 jar 中
【发布时间】:2014-01-31 08:56:51
【问题描述】:

我有一个用例,我需要使用 maven-buildHelper 插件将文件夹 target/schemas 包含为源文件夹。我正在为这个项目发起一场战争。创建源 jar 时,目标/模式的内容也存在于其中。我不想将目标/模式的内容添加到我的源 jar 中。如何实现?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-   instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupId>***************</groupId>
      <artifactId>core</artifactId>
      <version>1.0.0</version>
   </parent>

   <artifactId>identity</artifactId>
   <packaging>war</packaging>

   <dependencies>
       ...............
   </dependencies>

  <build>
     <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
           <execution>
              <id>attach-sources</id>
              <phase>verify</phase>
              <goals>
                 <goal>jar</goal>
              </goals>
           </execution>
        </executions>
     </plugin>

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
           <failOnMissingWebXml>false</failOnMissingWebXml>
           <warName>identity</warName>
        </configuration>
     </plugin>

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
           <execution>
              <id>unpack</id>
              <phase>prepare-package</phase>
              <goals>
                 <goal>unpack</goal>
              </goals>
              <configuration>
                 <artifactItems>
                    <artifactItem>
                       <groupId>***************</groupId>
                       <artifactId>authentication-service</artifactId>
                       <version>${project.version}</version>
                       <classifier>sources</classifier>
                       <type>jar</type>
                       <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                       <includes>**/*.java,**/*.xml</includes>
                    </artifactItem>
                    <artifactItem>
                       <groupId>***************</groupId>
                       <artifactId>authorization-service</artifactId>
                       <version>${project.version}</version>
                       <classifier>sources</classifier>
                       <type>jar</type>
                       <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                       <includes>**/*.java,**/*.xml</includes>
                    </artifactItem>
                 </artifactItems>
              </configuration>
           </execution>
        </executions>
     </plugin>
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${maven.plugin.buildHelper}</version>
        <executions>
           <execution>
              <id>add-source</id>
              <phase>generate-sources</phase>
              <goals>
                 <goal>add-source</goal>
              </goals>
              <configuration>
                 <sources>
                    <source>${project.build.directory}/schemas</source>
                 </sources>
              </configuration>
           </execution>
        </executions>
     </plugin>
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>${maven.plugin.jaxb2}</version>
        <executions>
           <execution>
              <id>schemagen-combined</id>
              <goals>
                 <goal>schemagen</goal>
              </goals>
              <phase>prepare-package</phase>
              <configuration>
                 <includes>
                    <include>***************/core/identity/domain/*.java</include>
                    <include>***************/authentication/domain/*.java</include>
                    <include>***************/authorization/domain/*.java</include>
                 </includes>
                 <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                 <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
              </configuration>
           </execution>

        </executions>
     </plugin
  </plugins>

我有一个 web 项目身份,它依赖于两个 jar 身份验证和授权。在项目身份中,我使用 jaxb2-maven-plugin 生成 xsd 用于身份验证、授权和身份源。作为插件 jaxb2-maven-plugin,仅适用于 maven 源路径中存在的源,我在文件夹 target/schema 中下载用于身份验证和授权的源,将此文件夹 target/schema 添加为 maven 源文件夹,然后运行 ​​jaxb2 -maven-plugin 生成 xsd。现在,当我为身份构建源 jar 时,它还包括我不想要的身份验证和授权源。

【问题讨论】:

  • 您到底想达到什么目的?将文件夹添加为源文件夹会按照它的说明进行操作。它添加它。为什么需要它作为源文件夹,但在生成的工件中不需要它?
  • 您是否尝试过使用测试资源文件夹? maven.apache.org/guides/introduction/…
  • 我有一个 web 项目标识,它依赖于两个 jar AuthN 和 AuthZ。在项目标识中,我使用 jaxb2-maven-plugin 为 AuthN 和 AuthZ 源生成 xsd。作为插件 jaxb2-maven-plugin,仅适用于 maven 源路径中存在的源,我在文件夹 target/schema 中下载 AuthN 和 AuthZ 的源,将此文件夹 target/schema 添加为 maven 源文件夹,然后运行 ​​jaxb2 -maven-plugin 生成 xsd。现在,当我为身份构建源 jar 时,它还包含我不想要的 AuthN 和 AuthZ 的源。

标签: java maven maven-plugin maven-assembly-plugin


【解决方案1】:

Maven Source plugin 具有从创建的源 JAR 中排除选定文件的选项。

exclude

要排除的文件列表。指定为文件集模式,这些模式与将其内容打包到 JAR 中的输入目录相关。

【讨论】:

  • 我真的很想对此投反对票;你不应该在源文件夹中生成文件!
  • 嗯,你是对的,等一下,修复即将到来:)
  • 我尝试了几个文件集选项,但似乎没有帮助。 target/schemas/**/*.java
  • 试试**/schemas/**/*.java
  • 发布 pom.xml 和完整日志
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-07
  • 1970-01-01
  • 2019-12-04
  • 2011-11-01
  • 2010-11-20
  • 1970-01-01
  • 2011-09-26
相关资源
最近更新 更多