13.4 Ant
使用Apache Ant+Ivy构建Spring Boot项目是可行的.spring-boot-antlib AntLib模块可以用来帮助Ant创建可执行的jar.
声明依赖关系,典型的ivy.xml文件看起来如下例子所示:
<ivy-module version="2.0"><info organisation="org.springframework.boot" module="spring-boot-sample-ant" /><configurations><conf name="compile" description="everything needed to compile this module" /><conf name="runtime" extends="compile" description="everything needed to run this module" /></configurations><dependencies><dependency org="org.springframework.boot" name="spring-boot-starter"rev="${spring-boot.version}" conf="compile" /></dependencies></ivy-module>
典型的build.xml文件看起来如下例子所示:
<projectxmlns:ivy="antlib:org.apache.ivy.ant"xmlns:spring-boot="antlib:org.springframework.boot.ant"name="myapp" default="build"><property name="spring-boot.version" value="2.0.2.RELEASE" /><target name="resolve" description="--> retrieve dependencies with ivy"><ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" /></target><target name="classpaths" depends="resolve"><path id="compile.classpath"><fileset dir="lib/compile" includes="*.jar" /></path></target><target name="init" depends="classpaths"><mkdir dir="build/classes" /></target><target name="compile" depends="init" description="compile"><javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" /></target><target name="build" depends="compile"><spring-boot:exejar destfile="build/myapp.jar" classes="build/classes"><spring-boot:lib><fileset dir="lib/runtime" /></spring-boot:lib></spring-boot:exejar></target></project>
Tip
如果你不想使用
spring-boot-antlib模块,请参考Section 86.9 Build an Executable Archive from Ant without Usingspring-boot-antlib
