Giriş
Bu yazıda maven aracının ana komutu olan mvn seçenekleri var.
Proje Yapısı - Boş ProjeŞöyledirproject
- pom.xml
- src/
- main/
- java/
- test/
Proje Yapısı - JARŞöyledirproject
- pom.xml
- src/
- main/
- java/
- resources/
- test/
- java/
- resources/
Proje Yapısı - WARŞöyledir.
src/main/java ve
src/main/webapp klasik war yapısı. Bu yapının dışına çıkmamak
lazım.
project
- pom.xml
- src/
- main/
- java/
- resources/
- webapp/
- WEB-INF/
- web.xml
- index.jsp
- css/
- styles.css
- test/
- java/
- resources/
MVN_HOME Ortam DeğişkeniŞöyledir. bin dizini gösterilmez.
C\apache-maven-3.5.0
RepositoryYolu
şöyledir. Yani kullanıcı ismim acelya ise "C:\acelya\.m2\repository" olur. jar dosyaları buraya indirilir.
{USER_HOME}\.m2\repository\
Yeni ProjeGroup Id : Şirket ismi. Yani "com.foo"
Artifact Id : Proje isi. Yani "MyProject"
Version : "1.0-SNAPSHOT" veya "1.0"
Package : "com.foo.myproject"
Lifecyclemaven Lifecycle Nedir yazısına taşıdım.
JVM ParametreleriAçıklaması
şöyle Several ways of configuring the JVM are available. The most straightforward way is to create a dedicated jvm.config configuration file in a .mvn subfolder in the project's folder.
Örnek
-XX:-TieredCompilation -XX:TieredStopAtLevel=1
Maven DaemonMaven da aynı Gradle gibi daemon kullanımına geçti. mvn komutu yerine mvnd komutunu kullanıyoruz. Bunun dışında seçenekler mvn komutu ile aynı
Örnek
Tüm seçeneklerSeçenek listesi
burada-am, --also-make >> If project list is specified, also build projects required by the listÖrnek ver
-amd ,--also-make-dependents >> If project list is specified, also build projects that depend on projects on the list
archetype:generate maven archetype seçeneği yazısına taşıdım
-B,--batch-mode >> Run in non-interactive (batch) mode (disables output color)Docker içinde kullanılabilir. Şöyle
yaparızRUN ./mvnw -B dependency:go-offline #1
-D ,--define >> Define a system property
Belirtilen değeri maven'a geçer yani
tanıtır.
-fn seçeneği
Açıklaması şöyleNEVER fail the build, regardless of project result
-help seçeneği
Şöyle yaparız.
mvn --help
-N seçeneği"Non-recursive" anlamına gelir. Alt projeleri çalıştırmaz. Şöyle
yaparızmvn -N io.takari:maven:wrapper
-o/ -offline seçeneği
Maven will check whether a SNAPSHOT dependency has a new "version" at every run. It means additional network roundtrips. We can prevent this check with the --offline option.
Örnek
Şöyle
yaparız.
mvn test -o
-P seçeneği
Belirtilen profile'ı
etkinleştirir. Açıklaması
şöyle.
-P,--activate-profiles <arg> >> Comma-delimited list of profiles to activate
Örnek
// profile name is unit-test for unit tests
mvn test -Punit-test
// profile name is integration-test for integration tests
mvn test -Pintegration-test
-pl seçeneği
mvn komutu -pl seçeneği yazısına taşıdım
-q seçeneğiquite anlamına gelir.Sadece hataları (error) gösterir. Şöyle
yaparız.
mvn -q compile exec:java
-s/--settings seçeneğiBelirtilen settings.xml dosyası kullanılır. Şöyle
yaparız.
$ mvn clean install --settings test/mvnsettings.xml
-T seçeneğiBu seçenek maven 3 ile geliyor. Normalde maven tek thread ile çalışır. Bu seçeneği kullanınca şuna benzer bir çıktı
alırız. Ayrıca bazı plugin'lere de işleri paralel yap emri de verilebiliyor. Örneğin surefire plugin testleri teker teker koşturur. Bunu da paralel hale getirmek mümkün.
Using the MultiThreadedBuilder implementation with a thread count of X
Eğer kullandığımız pluginlerden birisi paralel çalışması desteklemiyorsa maven uyarı verir. Çıktı olarak şunu
alırız.
[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project *
[WARNING] * contains the following plugin(s) that have goals not marked *
[WARNING] * as @threadSafe to support parallel building. *
[WARNING] * While this /may/ work fine, please look for plugin updates *
[WARNING] * and/or request plugins be made thread-safe. *
[WARNING] * If reporting an issue, report it against the plugin in *
[WARNING] * question, not against maven-core *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked @threadSafe in myBundle Install:
[WARNING] org.apache.karaf.tooling:karaf-services-maven-plugin:4.2.8
[WARNING] Enable debug to see more precisely which goals are not marked @threadSafe.
[WARNING] *****************************************************************
ÖrnekŞöyle
yaparızmvn clean install -DskipTests -T 2.0C
ÖrnekŞöyle
yaparız.
mvn -T 4 clean install # Builds with 4 threads
mvn -T 1C clean install # 1 thread per cpu core
mvn -T 1.5C clean install # 1.5 thread per cpu core
ÖrnekŞöyle
yaparız.
$ time mvn -T 4 clean install
-version seçeneğiAçıklaması
şöyle.
-v,--version >> Display version information
Şöyle
yaparız.
$ mvn -version
Apache Maven 3.2.2 ...
Maven home: c:\apache-maven-3.2.2
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: c:\Program Files\Java\jdk1.8.0_121\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"