(window.webpackJsonp=window.webpackJsonp||[]).push([[44],{471:function(e,t,a){"use strict";a.r(t);var r=a(56),s=Object(r.a)({},(function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h1",{attrs:{id:"build-tool-plugins"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#build-tool-plugins"}},[e._v("#")]),e._v(" Build Tool Plugins")]),e._v(" "),a("p",[e._v("Spring Boot provides build tool plugins for Maven and Gradle.\nThe plugins offer a variety of features, including the packaging of executable jars.\nThis section provides more details on both plugins as well as some help should you need to extend an unsupported build system.\nIf you are just getting started, you might want to read “"),a("RouterLink",{attrs:{to:"/en/spring-boot/using.html#using.build-systems"}},[e._v("using.html")]),e._v("” from the “"),a("RouterLink",{attrs:{to:"/en/spring-boot/using.html#using"}},[e._v("using.html")]),e._v("” section first.")],1),e._v(" "),a("h2",{attrs:{id:"_1-1-spring-boot-maven-plugin"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-1-spring-boot-maven-plugin"}},[e._v("#")]),e._v(" 1.1 Spring Boot Maven Plugin")]),e._v(" "),a("p",[e._v("The Spring Boot Maven Plugin provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application “in-place”.\nTo use it, you must use Maven 3.2 (or later).")]),e._v(" "),a("p",[e._v("See the plugin’s documentation to learn more:")]),e._v(" "),a("ul",[a("li",[a("p",[e._v("Reference ("),a("a",{attrs:{href:"https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/htmlsingle/",target:"_blank",rel:"noopener noreferrer"}},[e._v("HTML"),a("OutboundLink")],1),e._v(" and "),a("a",{attrs:{href:"https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/pdf/spring-boot-maven-plugin-reference.pdf",target:"_blank",rel:"noopener noreferrer"}},[e._v("PDF"),a("OutboundLink")],1),e._v(")")])]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/api/",target:"_blank",rel:"noopener noreferrer"}},[e._v("API"),a("OutboundLink")],1)])])]),e._v(" "),a("h2",{attrs:{id:"_1-2-spring-boot-gradle-plugin"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-2-spring-boot-gradle-plugin"}},[e._v("#")]),e._v(" 1.2. Spring Boot Gradle Plugin")]),e._v(" "),a("p",[e._v("The Spring Boot Gradle Plugin provides Spring Boot support in Gradle, letting you package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by "),a("code",[e._v("spring-boot-dependencies")]),e._v(".\nIt requires Gradle 6.8, 6.9, or 7.x.\nSee the plugin’s documentation to learn more:")]),e._v(" "),a("ul",[a("li",[a("p",[e._v("Reference ("),a("a",{attrs:{href:"https://docs.spring.io/spring-boot/docs/2.6.4/gradle-plugin/reference/htmlsingle/",target:"_blank",rel:"noopener noreferrer"}},[e._v("HTML"),a("OutboundLink")],1),e._v(" and "),a("a",{attrs:{href:"https://docs.spring.io/spring-boot/docs/2.6.4/gradle-plugin/reference/pdf/spring-boot-gradle-plugin-reference.pdf",target:"_blank",rel:"noopener noreferrer"}},[e._v("PDF"),a("OutboundLink")],1),e._v(")")])]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"https://docs.spring.io/spring-boot/docs/2.6.4/gradle-plugin/api/",target:"_blank",rel:"noopener noreferrer"}},[e._v("API"),a("OutboundLink")],1)])])]),e._v(" "),a("h2",{attrs:{id:"_3-spring-boot-antlib-module"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-spring-boot-antlib-module"}},[e._v("#")]),e._v(" 3. Spring Boot AntLib Module")]),e._v(" "),a("p",[e._v("The Spring Boot AntLib module provides basic Spring Boot support for Apache Ant.\nYou can use the module to create executable jars.\nTo use the module, you need to declare an additional "),a("code",[e._v("spring-boot")]),e._v(" namespace in your "),a("code",[e._v("build.xml")]),e._v(", as shown in the following example:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n ...\n\n')])])]),a("p",[e._v("You need to remember to start Ant using the "),a("code",[e._v("-lib")]),e._v(" option, as shown in the following example:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("$ ant -lib \n")])])]),a("blockquote",[a("p",[e._v("The “Using Spring Boot” section includes a more complete example of "),a("RouterLink",{attrs:{to:"/en/spring-boot/using.html#using.build-systems.ant"}},[e._v("using Apache Ant with "),a("code",[e._v("spring-boot-antlib")])]),e._v(".")],1)]),e._v(" "),a("h3",{attrs:{id:"_3-1-spring-boot-ant-tasks"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-1-spring-boot-ant-tasks"}},[e._v("#")]),e._v(" 3.1. Spring Boot Ant Tasks")]),e._v(" "),a("p",[e._v("Once the "),a("code",[e._v("spring-boot-antlib")]),e._v(" namespace has been declared, the following additional tasks are available:")]),e._v(" "),a("ul",[a("li",[a("p",[a("a",{attrs:{href:"#build-tool-plugins.antlib.tasks.exejar"}},[e._v("Using the “exejar” Task")])])]),e._v(" "),a("li",[a("p",[a("a",{attrs:{href:"#build-tool-plugins.antlib.findmainclass"}},[e._v("Using the “findmainclass” Task")])])])]),e._v(" "),a("h4",{attrs:{id:"_3-1-1-using-the-exejar-task"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-1-1-using-the-exejar-task"}},[e._v("#")]),e._v(" 3.1.1. Using the “exejar” Task")]),e._v(" "),a("p",[e._v("You can use the "),a("code",[e._v("exejar")]),e._v(" task to create a Spring Boot executable jar.\nThe following attributes are supported by the task:")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th",[e._v("Attribute")]),e._v(" "),a("th",[e._v("Description")]),e._v(" "),a("th",[e._v("Required")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[a("code",[e._v("destfile")])]),e._v(" "),a("td",[e._v("The destination jar file to create")]),e._v(" "),a("td",[e._v("Yes")])]),e._v(" "),a("tr",[a("td",[a("code",[e._v("classes")])]),e._v(" "),a("td",[e._v("The root directory of Java class files")]),e._v(" "),a("td",[e._v("Yes")])]),e._v(" "),a("tr",[a("td",[a("code",[e._v("start-class")])]),e._v(" "),a("td",[e._v("The main application class to run")]),e._v(" "),a("td",[e._v("No "),a("em",[e._v("(the default is the first class found that declares a "),a("code",[e._v("main")]),e._v(" method)")])])])])]),e._v(" "),a("p",[e._v("The following nested elements can be used with the task:")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th",[e._v("Element")]),e._v(" "),a("th",[e._v("Description")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[a("code",[e._v("resources")])]),e._v(" "),a("td",[e._v("One or more "),a("a",{attrs:{href:"https://ant.apache.org/manual/Types/resources.html#collection",target:"_blank",rel:"noopener noreferrer"}},[e._v("Resource Collections"),a("OutboundLink")],1),e._v(" describing a set of "),a("a",{attrs:{href:"https://ant.apache.org/manual/Types/resources.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("Resources"),a("OutboundLink")],1),e._v(" that should be added to the content of the created jar file.")])]),e._v(" "),a("tr",[a("td",[a("code",[e._v("lib")])]),e._v(" "),a("td",[e._v("One or more "),a("a",{attrs:{href:"https://ant.apache.org/manual/Types/resources.html#collection",target:"_blank",rel:"noopener noreferrer"}},[e._v("Resource Collections"),a("OutboundLink")],1),e._v(" that should be added to the set of jar libraries that make up the runtime dependency classpath of the application.")])])])]),e._v(" "),a("h4",{attrs:{id:"_3-1-2-examples"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-1-2-examples"}},[e._v("#")]),e._v(" 3.1.2. Examples")]),e._v(" "),a("p",[e._v("This section shows two examples of Ant tasks.")]),e._v(" "),a("p",[e._v("Specify start-class")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n \n \n \n \n\n')])])]),a("p",[e._v("Detect start-class")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n \n \n \n\n')])])]),a("h3",{attrs:{id:"_3-2-using-the-findmainclass-task"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-2-using-the-findmainclass-task"}},[e._v("#")]),e._v(" 3.2. Using the “findmainclass” Task")]),e._v(" "),a("p",[e._v("The "),a("code",[e._v("findmainclass")]),e._v(" task is used internally by "),a("code",[e._v("exejar")]),e._v(" to locate a class declaring a "),a("code",[e._v("main")]),e._v(".\nIf necessary, you can also use this task directly in your build.\nThe following attributes are supported:")]),e._v(" "),a("table",[a("thead",[a("tr",[a("th",[e._v("Attribute")]),e._v(" "),a("th",[e._v("Description")]),e._v(" "),a("th",[e._v("Required")])])]),e._v(" "),a("tbody",[a("tr",[a("td",[a("code",[e._v("classesroot")])]),e._v(" "),a("td",[e._v("The root directory of Java class files")]),e._v(" "),a("td",[e._v("Yes "),a("em",[e._v("(unless "),a("code",[e._v("mainclass")]),e._v(" is specified)")])])]),e._v(" "),a("tr",[a("td",[a("code",[e._v("mainclass")])]),e._v(" "),a("td",[e._v("Can be used to short-circuit the "),a("code",[e._v("main")]),e._v(" class search")]),e._v(" "),a("td",[e._v("No")])]),e._v(" "),a("tr",[a("td",[a("code",[e._v("property")])]),e._v(" "),a("td",[e._v("The Ant property that should be set with the result")]),e._v(" "),a("td",[e._v("No "),a("em",[e._v("(result will be logged if unspecified)")])])])])]),e._v(" "),a("h4",{attrs:{id:"_3-2-1-examples"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-2-1-examples"}},[e._v("#")]),e._v(" 3.2.1. Examples")]),e._v(" "),a("p",[e._v("This section contains three examples of using "),a("code",[e._v("findmainclass")]),e._v(".")]),e._v(" "),a("p",[e._v("Find and log")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("Find and set")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("p",[e._v("Override and set")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v('\n')])])]),a("h2",{attrs:{id:"_4-supporting-other-build-systems"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-supporting-other-build-systems"}},[e._v("#")]),e._v(" 4. Supporting Other Build Systems")]),e._v(" "),a("p",[e._v("If you want to use a build tool other than Maven, Gradle, or Ant, you likely need to develop your own plugin.\nExecutable jars need to follow a specific format and certain entries need to be written in an uncompressed form (see the “"),a("RouterLink",{attrs:{to:"/en/spring-boot/executable-jar.html#appendix.executable-jar"}},[e._v("executable jar format")]),e._v("” section in the appendix for details).")],1),e._v(" "),a("p",[e._v("The Spring Boot Maven and Gradle plugins both make use of "),a("code",[e._v("spring-boot-loader-tools")]),e._v(" to actually generate jars.\nIf you need to, you may use this library directly.")]),e._v(" "),a("h3",{attrs:{id:"_4-1-repackaging-archives"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-repackaging-archives"}},[e._v("#")]),e._v(" 4.1. Repackaging Archives")]),e._v(" "),a("p",[e._v("To repackage an existing archive so that it becomes a self-contained executable archive, use "),a("code",[e._v("org.springframework.boot.loader.tools.Repackager")]),e._v(".\nThe "),a("code",[e._v("Repackager")]),e._v(" class takes a single constructor argument that refers to an existing jar or war archive.\nUse one of the two available "),a("code",[e._v("repackage()")]),e._v(" methods to either replace the original file or write to a new destination.\nVarious settings can also be configured on the repackager before it is run.")]),e._v(" "),a("h3",{attrs:{id:"_4-2-nested-libraries"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-nested-libraries"}},[e._v("#")]),e._v(" 4.2. Nested Libraries")]),e._v(" "),a("p",[e._v("When repackaging an archive, you can include references to dependency files by using the "),a("code",[e._v("org.springframework.boot.loader.tools.Libraries")]),e._v(" interface.\nWe do not provide any concrete implementations of "),a("code",[e._v("Libraries")]),e._v(" here as they are usually build-system-specific.")]),e._v(" "),a("p",[e._v("If your archive already includes libraries, you can use "),a("code",[e._v("Libraries.NONE")]),e._v(".")]),e._v(" "),a("h3",{attrs:{id:"_4-3-finding-a-main-class"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-finding-a-main-class"}},[e._v("#")]),e._v(" 4.3. Finding a Main Class")]),e._v(" "),a("p",[e._v("If you do not use "),a("code",[e._v("Repackager.setMainClass()")]),e._v(" to specify a main class, the repackager uses "),a("a",{attrs:{href:"https://asm.ow2.io/",target:"_blank",rel:"noopener noreferrer"}},[e._v("ASM"),a("OutboundLink")],1),e._v(" to read class files and tries to find a suitable class with a "),a("code",[e._v("public static void main(String[] args)")]),e._v(" method.\nAn exception is thrown if more than one candidate is found.")]),e._v(" "),a("h3",{attrs:{id:"_4-4-example-repackage-implementation"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-4-example-repackage-implementation"}},[e._v("#")]),e._v(" 4.4. Example Repackage Implementation")]),e._v(" "),a("p",[e._v("The following example shows a typical repackage implementation:")]),e._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[e._v("import java.io.File;\nimport java.io.IOException;\nimport java.util.List;\n\nimport org.springframework.boot.loader.tools.Library;\nimport org.springframework.boot.loader.tools.LibraryCallback;\nimport org.springframework.boot.loader.tools.LibraryScope;\nimport org.springframework.boot.loader.tools.Repackager;\n\npublic class MyBuildTool {\n\n public void build() throws IOException {\n File sourceJarFile = ...\n Repackager repackager = new Repackager(sourceJarFile);\n repackager.setBackupSource(false);\n repackager.repackage(this::getLibraries);\n }\n\n private void getLibraries(LibraryCallback callback) throws IOException {\n // Build system specific implementation, callback for each dependency\n for (File nestedJar : getCompileScopeJars()) {\n callback.library(new Library(nestedJar, LibraryScope.COMPILE));\n }\n // ...\n }\n\n private List getCompileScopeJars() {\n return ...\n }\n\n}\n\n")])])]),a("h2",{attrs:{id:"_5-what-to-read-next"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-what-to-read-next"}},[e._v("#")]),e._v(" 5. What to Read Next")]),e._v(" "),a("p",[e._v("If you are interested in how the build tool plugins work, you can look at the "),a("a",{attrs:{href:"https://github.com/spring-projects/spring-boot/tree/v2.6.4/spring-boot-project/spring-boot-tools",target:"_blank",rel:"noopener noreferrer"}},[a("code",[e._v("spring-boot-tools")]),a("OutboundLink")],1),e._v(" module on GitHub.\nMore technical details of the executable jar format are covered in "),a("RouterLink",{attrs:{to:"/en/spring-boot/executable-jar.html#appendix.executable-jar"}},[e._v("the appendix")]),e._v(".")],1),e._v(" "),a("p",[e._v("If you have specific build-related questions, see the “"),a("RouterLink",{attrs:{to:"/en/spring-boot/howto.html#howto"}},[e._v("how-to")]),e._v("” guides.")],1)])}),[],!1,null,null,null);t.default=s.exports}}]);