简体   繁体   English

在maven中,将文件夹添加为源文件夹,但不要将其包含在源jar中

[英]In maven, add a folder as a source folder but dont include it in source jar

I have a use case where I need to include a folder target/schemas as a source folder using maven-buildHelper plugin. 我有一个用例,其中需要使用maven-buildHelper插件将文件夹target / schemas包含为源文件夹。 I am generating a war for this project. 我正在为此项目发动战争。 When the source jar get created, the content of target/schemas also exists in that. 创建源jar时,其中还存在目标/方案的内容。 I dont want add the content of target/schemas into my source jar. 我不想将目标/方案的内容添加到我的源jar中。 How can it be achieved ? 如何实现?

<?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>

I have a web project identity which depends on two jar authentication and authorization. 我有一个Web项目身份,这取决于两个jar身份验证和授权。 In project identity, I am generating xsd using jaxb2-maven-plugin for authentication, authorization and identity sources. 在项目标识中,我正在使用jaxb2-maven-plugin生成用于身份验证,授权和标识源的xsd。 As the plugin jaxb2-maven-plugin, works only on sources exists in the maven source path, I am downloading sources for authentication and authorization in a folder target/schema, add this folder target/schema as a maven source folder and then running jaxb2-maven-plugin to generate xsd. 由于插件jaxb2-maven-plugin仅适用于maven源路径中存在的源,因此我在目标/模式文件夹中下载用于身份验证和授权的源,将该目标/模式文件夹添加为maven源文件夹,然后运行jaxb2 -maven-plugin生成xsd。 Now, when I build source jar for identity, it also includes sources for authentication and authorization which I dont want. 现在,当我为身份构建源jar时,它还包括不需要的身份验证和授权源。

Maven Source plugin has option for excluding selected files from created source JAR. Maven Source插件具有用于从创建的源JAR中排除所选文件的选项。

exclude 排除

List of files to exclude. 要排除的文件列表。 Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR. 指定为相对于输入目录的文件集模式,其内容被打包到JAR中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM