使用 Ivy 下载 LWJGL natives

Downloading LWJGL natives with Ivy

我正在尝试为个人项目设置 Ant + Ivy 构建。在我到达 LWJGL 之前,一切都有意义,并且工作得很好。 LWJGL 的所有内容都已解决,本地人除外。

他们网站上的 Readme.md 似乎可以通过 Ivy 获得这些:

LWJGL 3 can be used with Maven/Gradle/Ivy, with the following dependencies:

  • org.lwjgl:lwjgl:${version}
  • org.lwjgl:lwjgl-platform:${version}:natives-windows
  • org.lwjgl:lwjgl-platform:${version}:natives-linux
  • org.lwjgl:lwjgl-platform:${version}:natives-osx

我要的文件肯定在maven central repository上,所以一定有办法通过ivy获取。我已经像这样设置了 ivy.xml 文件:

<ivy-module version="1.0" xmlns:extra="http://ant.apache.org/ivy/extra">
    <info organisation="foo" module="bar"/>
    <publications>
        <artifact name="baz" type="jar"/>
    </publications>
    <dependencies>
        <dependency org="org.lwjgl" name="lwjgl" rev="3.0.0a"/>
        <dependency org="org.lwjgl" name="lwjgl-platform" rev="3.0.0a" extra:classifier="natives-linux"/>
        <dependency org="org.lwjgl" name="lwjgl-platform" rev="3.0.0a" extra:classifier="natives-osx"/>
        <dependency org="org.lwjgl" name="lwjgl-platform" rev="3.0.0a" extra:classifier="natives-windows"/>
    </dependencies>
</ivy-module>

我在 ant 中的解决任务:

<target name="resolve" description="Retrive dependencies with Ivy">
    <ivy:retrieve/>
</target>

出于某种原因,这会从 "org.lwjgl:lwjgl:3.0.0a" 下载所有工件(jar、javadoc 和源代码),但不会从 "org.lwjgl:lwjgl-platform:3.0.0a" 下载任何本机。在Google上花了很长时间,终于在Github上找到了别人的ivy.xml文件中的"extra:classifier"语法,但无济于事(我抱有希望太早了)。一定有我遗漏的东西,所以我希望 SO 上的人能提供帮助。

必须在 ivy 依赖声明中显式检索 Maven 模块中的额外工件。

您还需要指定检索任务中使用的模式,因为 "classifier" 是 Maven 特定的标记并且是可选的。

例子

├── build.xml
├── ivy.xml
└── target
    └── lib
        ├── lwjgl-3.0.0a.jar
        ├── lwjgl-platform-3.0.0a-natives-linux.jar
        ├── lwjgl-platform-3.0.0a-natives-osx.jar
        └── lwjgl-platform-3.0.0a-natives-windows.jar

build.xml

<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">

    <property name="build.dir" location="target"/>

    <target name="resolve">
        <ivy:retrieve pattern="${build.dir}/lib/[artifact]-[revision](-[classifier]).[ext]"/>
    </target>

</project>

ivy.xml

<ivy-module version="1.0" xmlns:extra="http://ant.apache.org/ivy/extra">
  <info organisation="foo" module="bar"/>
  <dependencies>
    <dependency org="org.lwjgl" name="lwjgl" rev="3.0.0a" conf="default"/>

    <dependency org="org.lwjgl" name="lwjgl-platform" rev="3.0.0a">
      <artifact name="lwjgl-platform" type="jar" extra:classifier="natives-linux"/>
      <artifact name="lwjgl-platform" type="jar" extra:classifier="natives-osx"/>
      <artifact name="lwjgl-platform" type="jar" extra:classifier="natives-windows"/>
    </dependency>
  </dependencies>
</ivy-module>