【问题标题】:Generate different artifacts based on operating system for Maven using profiles使用配置文件为 Maven 生成基于操作系统的不同工件
【发布时间】:2016-08-10 22:19:54
【问题描述】:

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

  1. 无法识别的标签:'profiles'(位置:已看到 START_TAG ...\r\n ... C:\test-app\pom.xml,第 33 行,第 19 列
  2. 未知包装:nar @ line 15, column 16

我的 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>

【问题讨论】:

  • 将配置文件移出&lt;build&gt;标签...

标签: maven build


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 2010-10-17
    • 2020-05-11
    • 1970-01-01
    • 2023-03-10
    • 2012-10-12
    相关资源
    最近更新 更多