使用配置文件为Maven的操作系统生成不同的工件

时间:2016-08-09 23:15:59

标签: maven build

我正在尝试根据使用配置文件的操作系统生成不同的工件,但是当我运行 mvn validate 时,它会出现以下错误

  1. 无法识别的标签:'个人资料'(位置:START_TAG见过...... \ r \ n ... C:\ test-app \ pom.xml,第33行,第19栏
  2. 未知包装:nar @ line 15,第16栏
  3. 我的POM.xml如下所示。 nar-maven-plugin 在两个操作系统之间很常见。

    我无法弄清楚这里有什么问题。任何帮助都将受到高度赞赏。

    <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>com.company</groupId>
        <artifactId>mvn-test</artifactId>
        <version>1.0</version>
    </parent>
    
    <groupId>com.company.mvn-test</groupId>
    <artifactId>test-app</artifactId>
    <packaging>nar</packaging>
    <version>1.0-SNAPSHOT</version>
    
    <properties>
        <skipTests>true</skipTests>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>com.company.mvn-test</groupId>
            <artifactId>test-library</artifactId>
            <type>nar</type>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <defaultGoal>integration-test</defaultGoal>
        <profiles>
    
            <plugins>
                <plugin>
                    <groupId>com.github.maven-nar</groupId>
                    <artifactId>nar-maven-plugin</artifactId>
                    <version>3.2.3</version>
                    <extensions>true</extensions>
                    <configuration>
                        <libraries>
                            <library>
                                <type>executable</type>
                                <run>true</run>
                            </library>
                        </libraries>
                        <linker>
                            <name>g++</name>
                        </linker>
                    </configuration>
                </plugin>
            </plugins>
    
            <profile>
                <id>OS1</id>
                <activation>
                    <os>
                        <family>Windows</family>
                    </os>
                </activation>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <tasks>
                                        <copy todir="bin" flatten="true">
                                            <fileset dir="target">
                                                <include name="**/*dll"/>
                                            </fileset>
                                        </copy>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </profile>
    
            <profile>
                <id>OS2</id>
                <activation>
                    <os>
                        <family>unix</family>
                    </os>
                </activation>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <tasks>
                                        <copy todir="bin" flatten="true">
                                            <fileset dir="target">
                                                <include name="**/*so"/>
                                                <include name="**/*test-app"/>
                                            </fileset>
                                        </copy>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </profile>
    
        </profiles>
    </build>
    

1 个答案:

答案 0 :(得分:1)

试试这个 -

<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>com.company</groupId>
    <artifactId>mvn-test</artifactId>
    <version>1.0</version>
</parent>

<groupId>com.company.mvn-test</groupId>
<artifactId>test-app</artifactId>
<packaging>nar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
    <skipTests>true</skipTests>
</properties>

<dependencies>
    <dependency>
        <groupId>com.company.mvn-test</groupId>
        <artifactId>test-library</artifactId>
        <type>nar</type>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

<build>
    <defaultGoal>integration-test</defaultGoal>
    <plugins>
        <plugin>
            <groupId>com.github.maven-nar</groupId>
            <artifactId>nar-maven-plugin</artifactId>
            <version>3.2.3</version>
            <extensions>true</extensions>
            <configuration>
                <libraries>
                    <library>
                        <type>executable</type>
                        <run>true</run>
                    </library>
                </libraries>
                <linker>
                    <name>g++</name>
                </linker>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>OS1</id>
        <activation>
            <os>
                <family>Windows</family>
            </os>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <configuration>
                                <tasks>
                                    <copy todir="bin" flatten="true">
                                        <fileset dir="target">
                                            <include name="**/*dll"/>
                                        </fileset>
                                    </copy>
                                </tasks>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>OS2</id>
        <activation>
            <os>
                <family>unix</family>
            </os>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <configuration>
                                <tasks>
                                    <copy todir="bin" flatten="true">
                                        <fileset dir="target">
                                            <include name="**/*so"/>
                                            <include name="**/*test-app"/>
                                        </fileset>
                                    </copy>
                                </tasks>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
</project>