maven etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
maven etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

15 Ağustos 2021 Pazar

maven Transitive Dependencies

Giriş
Farklı modüllerden bir kütüphanenin farklı sürümleri transitive dependency olarak geliyor olabilir. 
Bu durumda kök (root) düğüme en yakın olan kullanılır.

Örnek
Elimizde şöyle bir ağaç olsun
  A
  ├── B
  │   └── C
  │       └── D 2.0
  └── E
      └── D 1.0

Bu durumda D1.0 tercih edilir. Maven mesaj olarak "omitted for conflict with .." şeklinde bir mesaj verir.

Eğer D2.0 ı kullanmayı mecbur yapmak istersek, D bağımlılığı elle eklenir. Bu durumda pom.xml şöyle olur
 A
  ├── B
  │   └── C
  │       └── D 2.0
  ├── E
  │   └── D 1.0
  │
  └── D 2.0      


3 Kasım 2020 Salı

maven pom.xml modules tag - Project Aggregation İçindir veya Multimodule Project

Giriş
Bu tag ana proje (parent proje)pom.xml dosyasında kullanılır. Proje'ye ait alt modülleri belirtir. Açıklaması şöyle
When you create a module, you must specify a parent project. When you specify the parent project, it adds a <modules> section to the parent projects pom.xml. That section basically says to the parent project, "run every command I get against all of my modules first". So if you run, "mvn package" on the top level project, it will run "mvn package" against all it's module projects first.
Ayrıca parent projedeki paketleme tipi pom olmalıdır. Açıklaması şöyle
The main difference between multi-module parent pom and normal pom is its packaging type. For a multi-module parent pom, its packaging type becomes ‘pom’.
<packaging>pom</packaging>

Also in parent pom, it is referring to the submodules with <submodule> tag.

<modules>
  <module>email-service</module>
  <module>frontend</module>
  <module>data-service</module>
 </modules>
Maven modüller arasındaki bağımlılıkları da kendisi hallediyor. Açıklaması şöyle
When Maven is executed against a project with submodules, Maven first loads the parent POM and locates all of the submodule POMs. Maven then puts all of these project POMs into something called the Maven Reactor which analyzes the dependencies between modules. The Reactor takes care of ordering components to ensure that interdependent modules are compiled and installed in the proper order.
...
Once the Reactor figures out the order in which projects must be built, Maven then executes the specified goals for every module in the multi-module build.
Ben şu yapıda kullandım.
myproject/
  myproject-core/
  myproject-api/
  myproject-app/
  pom.xml
Örnek
Ana proje (A) ve bunun B,C alt projeleri olsun. A projesinde şöyle yaparız
<project ...>

  <groupId>com.foo.bar</groupId>
  <artifactId>parent</artifactId>
  <packaging>pom</packaging>
  <version>2.3.0</version>

  <modules>
    <module>B</module>
    <module>C</module>
  </modules>

  <dependencyManagement>
    ...
  </dependencyManagement>
</project>
Burada packaging olarak pom seçiliyor. Açıklaması şöyle. Çünkü ana projenin bir jar üretmesi beklenmiyor.
The parent project doesn’t create a JAR or a WAR like our previous projects; instead, it is simply a POM that refers to other Maven projects. The appropriate packaging for a project like simple-parent that simply provides a Project Object Model is pom.


4 Ağustos 2020 Salı

maven Phase Nedir

Giriş
Her Life Cycle phase'lerden oluşur. 

Phase'i Tetiklemek
Şöyle yaparız
mvn <phase> { Ex: mvn install }
Birden fazla phase'i tetiklemek için şöyle yaparız.
mvn clean generate-sources
validate phase
Açıklaması şöyle
validate the project is correct and all necessary information is available
compile phase
Açıklaması şöyle
compile the source code of the project
test phase
Açıklaması şöyle
test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package phase
Açıklaması şöyle
take the compiled code and package it in its distributable format, such as a JAR.
Örnek
Şöyle yaparız. Projemiz /target dizini altında .jar veya hangi paket tipini belirttiysek o tipte hazırlanır.
mvn clean package
java -jar target/hello-world-docker-1.0-SNAPSHOT.jar
Hello World from Docker! #output
Örnek
Şöyle yaparız
./mvnw clean package -Dpackaging=native-image
integration-test phase
Açıklaması şöyle
process and deploy the package if necessary into an environment where integration tests can be run
install phase
Açıklaması şöyle
install the package into the local repository, for use as a dependency in other projects locally
Örnek
Şöyle yaparız
mvn install:install-file 
  -Dfile=user-details-proto-1.0-SNAPSHOT.jar 
  -DgroupId=com.userdetails.model 
  -DartifactId=user-details-proto 
  -Dversion=1.0-SNAPSHOT 
  -Dpackaging=jar
deploy phase
Açıklaması şöyle
done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
Deployment tamamen otomatik olmalı. Açıklaması şöyle
Best Practice is to automate your deployment, completely and exclusively. That means nobody gets to put anything onto a server manually.
Şöyle yaparız.
mvn deploy

18 Şubat 2020 Salı

maven settings.xml

Giriş
İki tane settings.xml olabilir. Açıklaması şöyle
Maven always uses either one or two settings files. The global settings defined in (${M2_HOME}/conf/settings.xml) is always required. The user settings file (defined in ${user.home}/.m2/settings.xml) is optional. Any settings defined in the user settings take precedence over the corresponding global settings.
Benim Windows sistemimde MVN_HOME=C:\apache-maven-3.5.0 olarak tanımlı ve bu dizindeki global conf/settings.xml'i ellemiyorum.

"C:\Users\acelya\.m2\settings.xml" dosyasını düzenleyerek ayarları yapıyorum. Maven'de herşeyi
"C:\Users\acelya\.m2\repository" dizinine indiriyor.
Yapısı
Şöyledir
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <pluginGroups />
  <proxies />
  <servers>

    <server>
    ...
    </server>
    <server>
      ...
    </server>
    
  </servers>

  <mirrors />

  <profiles>
    <profile>
      <repositories>
        <repository>
          ...
        </repository>
      </repositories>
     </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>companydev</activeProfile>
  </activeProfiles>

</settings>
pluginGroups,proxies,servers,mirrors,profiles,activeProfiles taglerini içerir.

mirror tag
Maven pom'ları içinde - örneğin Spring kullanıyorsak - diğer repository'lere atıfta bulunulur. Eğer kapalı bir ortamda çalışıyorsak bu repository'lere erişim mümkün değildir. Bu repository'leri mirror'ladığımızı belirtmek için kullanılır. Şöyle yaparız
<mirror>
  <id>mymirror</id>
  <url>http://myserver:8080/...</url>
  <mirrorOf>*,!myrepo1, !myrepo2</mirrorOf>
</mirror>
profile tag
profiles tag içindedir. İçinde repository ve properties barındırır.
Örnek
Şöyle yaparız.
<profile>
  <id>companydev</id>

  <properties>
    <unit-test-ldap-server-host>mis-dev</unit-test-ldap-server-host>
    <unit-test-database-url>jdbc:mysql://mis-dev:1234/unit_test</unit-test-database-url>
  </properties>

  <repositories>
    <repository>
      ...
    </repository>
  </repositories>
</profile>
proxies tag
Maven tarafından kullanılacak proxy sunucusu belirtilir.
Örnek
Şöyle yaparız
<settings>
  <proxies>
   <proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>
repository tag
repositories tag yazısına taşıdım.

server tag
repositories tag yazısına taşıdım.

16 Ocak 2020 Perşembe

maven pom.xml repositories tag

repositories tag
Maven merkezi repository dışında daha farklı bir repository eklemek istersek kullanırız.

URL Tag
Örnek
Şöyle yaparız.
<repositories>
  <repository>
    <id>my-internal-site</id>
    <url>http://myserver/repo</url>
  </repository>
</repositories>
Örnek
Central Repository için https kullanmak gerekir. Açıklaması şöyle.
Effective January 15, 2020, The Central Repository no longer supports insecure communication over plain HTTP and requires that all requests to the repository are encrypted over HTTPS.
Şöyle yaparız.
<repositories>
   <repository>
      <id>central maven repo</id>
      <name>central maven repo https</name>
      <url>https://repo.maven.apache.org/maven2</url>
   </repository>
</repositories>
Örnek - dosya Sistemi
Dosya sistem için şöyle yaparız.
<repositories>
  <repository>
    <id>local-repo</id>
    <url>file:///${project.basedir}/repo</url>
  </repository>
</repositories>
releases ve snapshots Tag
Örnek 
Şöyle yaparız.
<repositories>
  <repository>
    <id>maven.oracle.com</id>
    <releases> 
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
   <url>https://maven.oracle.com</url>
  </repository>
</repositories>
server tag
servers tag içindedir. Açıklaması şöyle.
Some artifact repositories require a username and password to access. Many times, the repository is a private server hosting internal artifacts. When this is the case, credentials for accessing the repository must be provided in the settings.xml,
Deploy edilecek Nexus şifresi kullanılır.
Örnek
Şöyle yaparız. id alanı ile repository id alanı aynı olmalı.
<profile>
  <repositories>
    <repository>
      <id>...</id>
      ...
    <repository>
  <repositories>
<profile>
<server>     
  <id>myrepo_Snapshots</id>
  <username>admin</username>
  <password>xxxx</password>
</server>