Getting Started with Maven | Creating a Maven Project | Maven Goal
In the previous section, we were able to create and run a program. Here, we will explain the “goal” that we briefly passed over earlier.
About Maven Goals
To build the program, we ran the command mvn package. Earlier, we mentioned that this package is called a goal.
A goal represents a “role of processing” in Maven. Maven specifies what role of processing should be executed. That is a goal.
When we first created the project, we ran the command mvn archetype:generate. This also executed a goal called archetype:generate.
(Strictly speaking, archetype is a plugin, and it executes the plugin’s generate goal.)
When Maven does something, it first clarifies “what to do” (this is the goal). Then, when you enter the arguments and information required to execute it, the processing for the specified goal runs. Knowing what goals exist is also necessary for understanding Maven.
For now, at this stage, remember only the following basic goals.
package
This goal has already been used and is for creating a package. It internally runs compile, test-compile, and test.
compile
Compiles the program. However, it does not create a Jar file.
test-compile
Compiles the test program. It compiles the source code in the test folder under src.
test
Runs tests. It executes the test program prepared in the test folder under src.
clean
Deletes all files generated by compilation. Use this when you want to remove unnecessary files created by compilation.
There are many other goals. There are also goals added by plugins, such as archetype:generate. Other goals will be explained as needed.