Bootstraps a Maven project. Because archetypes shouldn’t be so complicated.
- [travis-ci.org/tychobrailleur/mvnizer][https://travis-ci.org/tychobrailleur/mvnizer.svg?branch=master]
- [badge.fury.io/rb/mvnizer][https://badge.fury.io/rb/mvnizer.svg]
-
Introduction
Mvnizer
is ideal to create a throwaway Maven project that adds junit as a dependency and sets up the Maven project structure. -
Install
Mvnizer
can be installed as follows:
+BEGIN_EXAMPLE
$ gem install mvnizer
+END_EXAMPLE
-
Commands
** Project Creation
Mvnizer is used as follows:
+BEGIN_EXAMPLE
$ mvnizer new <coordinates>
+END_EXAMPLE
The coordinates can have the following format:
+BEGIN_EXAMPLE
<group:>artifact<:version><:type>
+END_EXAMPLE
with the values between angled brackets optional. =type= can only have one of the following three values: =jar= (default), =war= or =pom=. This command creates a project in the =artifact= folder, populating the proper values in the pom file.
Here are some examples of valid commands:
+BEGIN_EXAMPLE
mvnizer new foo mvnizer new foo:war mvnizer new foo:1.0.0:war mvnizer new com.example:foo mvnizer new com.example:foo:war mvnizer new com.example:foo:1.0.0:war
+END_EXAMPLE
The version must be of the form =major.minor.patch-classifier=.
*** Options
The following options can be used to add specific files to the project: - =--docker= :: this creates a =Dockerfile= based on the Java 11 distroless base image. It assumes that the jar generated by the build can be executed using the =java -jar= command; - =--main=[Main class name] :: this creates a class with a =main= method that can be executed using the =java -jar= command. It also adds the =maven-shade-plugin= to the pom, with this class as the main class. - =--logger= :: this adds logging dependencies to the project. The jar added are defined as the =logging_deps= of the configuration file. The default are: #+begin_src
logging_deps: [ “org.slf4j:slf4j-api:1.7.32:jar”,
"org.slf4j:slf4j-simple:1.7.32:jar", "ch.qos.logback:logback-core:1.2.6:jar" ] #+end_src
*** WAR Project
If the type of project generated is =war=, a servlet (=ExampleServlet=) is generated, along with a JSP file and an empty =web.xml= file. When running the Jetty plugin, /e.g./:
+BEGIN_EXAMPLE mvn org.eclipse.jetty:jetty-maven-plugin:9.4.12.v20180830:run-war +END_EXAMPLE
The example can then be accessed at http://localhost:8080/hello
** Add Dependency
To add dependencies, you must be in the folder where the pom file you want to add the dependency to is. To add a dependency, simply pass the coordinates of the dependency, and add scope if needed (if no scope is given, =compile= is assumed):
+BEGIN_EXAMPLE
mvnizer add org.apache.commons:commons-lang3:3.1:jar mvnizer add org.mockito:mockito-core:1.9.5-rc1:jar:test
+END_EXAMPLE
The =search= features makes it easy to find the coordinates of the dependencies for you.
** Dependency Search
You can search for dependencies in the Maven central repository with the command:
+BEGIN_EXAMPLE
$ mvnizer search <text>
+END_EXAMPLE
-
License
MIT License.
© Copyright 2012–2021 — Sébastien Le Callonnec