[[using]]
= Using the Plugin

Maven users can inherit from the `spring-boot-starter-parent` project to obtain sensible defaults.
The parent project provides the following features:

* Java 17 as the default compiler level.
* UTF-8 source encoding.
* Compilation with `-parameters`.
* A dependency management section, inherited from the `spring-boot-dependencies` POM, that manages the versions of common dependencies.
This dependency management lets you omit `<version>` tags for those dependencies when used in your own POM.
* An execution of the xref:maven-plugin:packaging.adoc#packaging.repackage-goal[`repackage` goal] with a `repackage` execution id.
* A `native` profile that configures the build to be able to generate a Native image.
* Sensible https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html[resource filtering].
* Sensible plugin configuration (https://github.com/ktoso/maven-git-commit-id-plugin[Git commit ID], and https://maven.apache.org/plugins/maven-shade-plugin/[shade]).
* Sensible resource filtering for `application.properties` and `application.yml` including profile-specific files (for example, `application-dev.properties` and `application-dev.yml`)

NOTE: Since the `application.properties` and `application.yml` files accept Spring style placeholders (`${...}`), the Maven filtering is changed to use `@..@` placeholders.
(You can override that by setting a Maven property called `resource.delimiter`.)

[NOTE]
====
The `spring-boot-starter-parent` sets the `maven.compiler.release` property, which restricts the `--add-exports`, `--add-reads`, and `--patch-module` options https://openjdk.org/jeps/247[if they modify system modules].
In case you need to use those options, unset `maven.compiler.release`:

[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<maven.compiler.release></maven.compiler.release>
----

and then configure the source and the target options instead:

[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
----
====



[[using.parent-pom]]
== Inheriting the Starter Parent POM

To configure your project to inherit from the `spring-boot-starter-parent`, set the `parent` as follows:

[source,xml,subs="verbatim,quotes,attributes"]
----
<!-- Inherit defaults from Spring Boot -->
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>{version-spring-boot}</version>
</parent>
----

NOTE: You should need to specify only the Spring Boot version number on this dependency.
If you import additional starters, you can safely omit the version number.

With that setup, you can also override individual dependencies by overriding a property in your own project.
For instance, to use a different version of the SLF4J library and the Spring Data release train, you would add the following to your `pom.xml`:

[source,xml,indent=0,subs="verbatim,attributes"]
----
include::example$using/different-versions-pom.xml[tags=different-versions]
----

Browse the xref:appendix:dependency-versions/properties.adoc[Dependency Versions Properties] section in the Spring Boot reference for a complete list of dependency version properties.



[[using.import]]
== Using Spring Boot without the Parent POM

There may be reasons for you not to inherit from the `spring-boot-starter-parent` POM.
You may have your own corporate standard parent that you need to use or you may prefer to explicitly declare all your Maven configuration.

If you do not want to use the `spring-boot-starter-parent`, you can still keep the benefit of the dependency management (but not the plugin management) by using an `import` scoped dependency, as follows:

[source,xml,indent=0,subs="verbatim,attributes"]
----
include::example$using/no-starter-parent-pom.xml[tags=no-starter-parent]
----

The preceding sample setup does not let you override individual dependencies by using properties, as explained above.
To achieve the same result, you need to add entries in the `dependencyManagement` section of your project **before** the `spring-boot-dependencies` entry.
For instance, to use a different version of the SLF4J library and the Spring Data release train, you could add the following elements to your `pom.xml`:

[source,xml,indent=0,subs="verbatim,attributes"]
----
include::example$using/no-starter-parent-override-dependencies-pom.xml[tags=no-starter-parent-override-dependencies]
----



[[using.overriding-command-line]]
== Overriding Settings on the Command Line

The plugin offers a number of user properties, starting with `spring-boot`, to let you customize the configuration from the command line.

For instance, you could tune the profiles to enable when running the application as follows:

[source,shell]
----
$ mvn spring-boot:run -Dspring-boot.run.profiles=dev,local
----

If you want to both have a default while allowing it to be overridden on the command line, you should use a combination of a user-provided project property and MOJO configuration.

[source,xml,indent=0,subs="verbatim,attributes"]
----
include::example$using/default-and-override-pom.xml[tags=default-and-override]
----

The above makes sure that `local` and `dev` are enabled by default.
Now a dedicated property has been exposed, this can be overridden on the command line as well:

[source,shell]
----
$ mvn spring-boot:run -Dapp.profiles=test
----
