13.4 Ant

使用Apache Ant+Ivy构建Spring Boot项目是可行的.spring-boot-antlib AntLib模块可以用来帮助Ant创建可执行的jar. 声明依赖关系,典型的ivy.xml文件看起来如下例子所示:

  1. <ivy-module version="2.0">
  2.   <info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
  3.   <configurations>
  4.     <conf name="compile" description="everything needed to compile this module" />
  5.     <conf name="runtime" extends="compile" description="everything needed to run this module" />
  6. </configurations>
  7.   <dependencies>
  8.     <dependency org="org.springframework.boot" name="spring-boot-starter"
  9.     rev="${spring-boot.version}" conf="compile" />
  10.   </dependencies>
  11. </ivy-module>

典型的build.xml文件看起来如下例子所示:

  1. <project
  2. xmlns:ivy="antlib:org.apache.ivy.ant"
  3. xmlns:spring-boot="antlib:org.springframework.boot.ant"
  4. name="myapp" default="build">
  5. <property name="spring-boot.version" value="2.0.2.RELEASE" />
  6. <target name="resolve" description="--> retrieve dependencies with ivy">
  7. <ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />
  8. </target>
  9. <target name="classpaths" depends="resolve">
  10. <path id="compile.classpath">
  11. <fileset dir="lib/compile" includes="*.jar" />
  12. </path>
  13. </target>
  14. <target name="init" depends="classpaths">
  15. <mkdir dir="build/classes" />
  16. </target>
  17. <target name="compile" depends="init" description="compile">
  18. <javac srcdir="src/main/java" destdir="build/classes" classpathref="compile.classpath" />
  19. </target>
  20. <target name="build" depends="compile">
  21. <spring-boot:exejar destfile="build/myapp.jar" classes="build/classes">
  22. <spring-boot:lib>
  23. <fileset dir="lib/runtime" />
  24. </spring-boot:lib>
  25. </spring-boot:exejar>
  26. </target>
  27. </project>

Tip

如果你不想使用spring-boot-antlib模块,请参考Section 86.9 Build an Executable Archive from Ant without Using spring-boot-antlib