代码之家  ›  专栏  ›  技术社区  ›  Brick

使用MinGW编译器和nar-maven插件避免机器相关的POM

  •  1
  • Brick  · 技术社区  · 8 年前

    nar-maven-plugin

    maven install 通过Eclipse IDE,我需要在POM文件中明确指定链接器,作为插件的一部分 configuration 相关章节如下:

            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.5.1</version>
                <extensions>true</extensions>
                <configuration>
                    <linker>
                        <name>g++</name>
                        <options>
                            <option>-Wl,--kill-at</option>
                        </options>
                    </linker>
                    <libraries>
                        <library>   
                            <type>jni</type>
                            <narSystemPackage>com.mycompany.sandbox</narSystemPackage>
                        </library>
                    </libraries>
                </configuration>
            </plugin>
    

    [INFO] --- nar-maven-plugin:3.5.1:nar-validate (default-nar-validate) @ nar-test ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.786 s
    [INFO] Finished at: 2017-06-29T17:05:34-04:00
    [INFO] Final Memory: 8M/23M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal com.github.maven-nar:nar-maven-plugin:3.5.1:nar-validate (default-nar-validate) on project nar-test: Execution default-nar-validate of goal com.github.maven-nar:nar-maven-plugin:3.5.1:nar-validate failed. NullPointerException -> [Help 1]
    

    <name>g++</name> 分割并删除选项,然后编译,但我的测试失败,因为它无法在运行时链接到本机实现。(这与 --kill-at 国旗和一个已知的问题,所以这不是一个可怕的惊喜。)

    有没有一种已知的方法来处理这个问题,这样我就可以得到一个独立于机器的POM来工作?

    2 回复  |  直到 8 年前
        1
  •  1
  •   Gerold Broser    8 年前

    这是的典型用例 Build Profiles :

    因此,将不同的插件配置放入配置文件中,并在构建时相应地激活它们。

    另一种方法是使用以下属性:

    <option>${options}</option>
    

    其定义值如下:

    mvn ... -Doptions=-Wl,--kill-at
    
        2
  •  1
  •   Brick    8 年前

    Gerold Broser的答案似乎与我想要的相反,但它确实让我走上了使用配置文件的正确道路。对我来说,其中一个诀窍是认识到,可以在概要文件中对单个插件进行部分规范,而将同一插件的其他参数放在主概要文件中 build activeByDefault 在我的默认设置上,而不是使用 activeProfiles

    为完整起见,工作POM的相关部分如下:

    <profiles>
        <!-- This default not needed since is specifies nothing, but this seems to be the correct syntax if it were needed
        <profile>
            <id>Default-CPP-Tools</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        -->
    
        <profile>
            <id>Windows-MinGW</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.maven-nar</groupId>
                        <artifactId>nar-maven-plugin</artifactId>
                        <version>3.5.1</version>
                        <extensions>true</extensions>
                        <configuration>
                            <linker>
                                <name>g++</name>
                                <options>
                                    <option>-Wl,--kill-at</option>
                                </options>
                            </linker>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    
    <build>
        <defaultGoal>integration-test</defaultGoal>
    
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.5.1</version>
                <extensions>true</extensions>
                <configuration>
                    <libraries>
                        <library>
                            <type>jni</type>
                            <narSystemPackage>com.mycompany.sandbox</narSystemPackage>
                        </library>
                    </libraries>
                </configuration>
            </plugin>
        </plugins>
    
    </build>