Maven为不同名称的项目创建同一个jar的副本以用于sping项目

时间:2019-07-08 14:26:13

标签: maven spring-boot

由于某些要求,我有一个春季项目,我必须创建不同名称的罐子副本。

当前,我正在根据要求进行构建和重命名,我需要在打包期间在pom中自动执行该操作。

我在pom下面尝试过,但是它仅创建默认的jar 无论如何,我们可以分配名称来创建相同代码的多个jar副本


    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycode.userservice</groupId>
    <artifactId>user-service-app</artifactId>
    <version>1.0.2-RELEASE</version>
    <name>UserService</name>
    <properties>
        <spring-boot.version>2.0.0.RELEASE</spring-boot.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>
        <dependencyManagement>
        <dependencies>

            <!-- Spring Boot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Spring Cloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <!-- Spring Boot dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
 <execution>
        <id>build-first</id>
          <configuration>
           <attachToBuild>true</attachToBuild>
            <filename>mainuser.jar</filename>
          </configuration>
          <goals>
            <goal>repackage<</goal>
          </goals>
        </execution>
      <execution>
        <id>build-second</id>
          <configuration>
            <attachToBuild>true</attachToBuild>
            <filename>alternative-user.jar</filename>
          </configuration>
          <goals>
            <goal>repackage<</goal>
          </goals>
        </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

仅构建默认 jar,而不构建 alternative-user.jar mainuser.jar

0 个答案:

没有答案