28 Aralık 2022 Çarşamba

pluginRepositories tag

Örnek
Şöyle yaparız
<project ...>
  <parent>
    ...
  </parent>
  <properties>
    ...
  </properties>
  <dependencies>
    ...
  </dependencies>
  <build>
    <plugins>
    ...
    </plugins>
  </build>

  <repositories>
    ...
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>spring-libs-milestone</id>
      <url>https://repo.spring.io/libs-milestone</url>
    </pluginRepository>
  </pluginRepositories>
</project>

repositories tag - Şirketin Repository Sunucusunu Belirtirtir

Giriş
Açıklaması şöyle
In Maven we have 3 types of repositories

1. Central Repository
2. Remote Repository
3. Local Repository

Central repository is maintained by Apache organization
Every company will maintain their own remote repository (Ex: Nexus, JFrog)
Local repository will be created in our system (Location : C://users/<uname>/.m2)
Örnek
Şöyle yaparız
<repositories>
<repository> <id>id</id> <url>jfrong-repo-url/</url> </repository> </repositories>
Örnek
Şöyle yaparız
<project ...>
  <parent>
    ...
  </parent>
  <properties>
    ...
  </properties>
  <dependencies>
    ...
  </dependencies>
  <build>
    <plugins>
    ...
    </plugins>
  </build>

  <repositories>
    <repository>
      <id>spring-libs-milestone</id>
      <url>https://repo.spring.io/libs-milestone</url>
    </repository>
  </repositories>

  <pluginRepositories>
    ...
  </pluginRepositories>
</project>

23 Aralık 2022 Cuma

native plugin - GraalVM İle Native Image Oluşturur

Goaller
build
compile-no-fork
release

Örnek
Sadece şöyle yapmak yeterli. maven install ile proje derlenir.
<plugin>
  <groupId>org.graalvm.buildtools</groupId>
  <artifactId>native-maven-plugin</artifactId>
</plugin>
Profile
Örnek
Bu plugin bazen bir profile ile kullanılıyor. Önce bir profile ekleriz
<profiles>
  <profile>
    <id>native</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.graalvm.buildtools</groupId>
          <artifactId>native-maven-plugin</artifactId>
          <executions>
            <execution>
              <id>build-native</id>
              <goals>
                <goal>compile-no-fork</goal>
              </goals>
              <phase>package</phase>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
</profile>
</profiles>
Daha sonra şöyle yaparız
./mvnw clean package -Pnative
Eğer plugin profile içinde değilse şöyle yaparız
./mvnw clean package -Dpackaging=native-image
Örnek 
Açıklaması şöyle
If you have not installed it to your own machine, you also have an option to use a Docker container that has GraalVM and the native image extension installed by default. You can use the following command for that: 

./mvnw package -Pnative -Dquarkus.native.container-build=true

It might take some time to finish compilation, especially in the docker container, but after a while you should have a native executable named code-with-quarkus-1.0.0.-SNAPSHOT-runner in your target folder.
Şöyle yaparız
./mvnw package -Pnative -Dquarkus.native.container-build=true
Örnek
Şöyle yaparız
<profile>
  <id>native</id>
  <activation>
    <property>
      <name>native</name>
    </property>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.graalvm.buildtools</groupId>
        <artifactId>native-maven-plugin</artifactId>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>build-native</id>
            <goals>
              <goal>build</goal>
            </goals>
            <phase>package</phase>
          </execution>
          <execution>
            <id>release-native</id>
            <goals>
              <goal>release</goal>
            </goals>
            <phase>release</phase>
          </execution>
        </executions>
        <configuration>
          <imageName>${appName}-${project.version}</imageName>
          <mainClass>${mainClass}</mainClass>
          <buildArgs>
            <buildArg>--allow-incomplete-classpath</buildArg>
            <buildArg>--no-fallback</buildArg>
            <buildArg>-H:+ReportExceptionStackTraces</buildArg>
            <buildArg>--verbose</buildArg>
          </buildArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>
Çalıştırmak için şöyle yaparız
./mvnw -B --file pom.xml -Pnative package
Açıklaması şöyle
When you run the resulting application, the application will report the Class files it is unable to find
...
You can then add them to the reflect-config.json in the resources/META-INF/native-image folder of your project.

And you specify the configuration in native-image.properties for GraalVM native-image-plugin to refer the reflect-config.json while building the native image.

-H=ReflectionConfigurationResources=${.}/reflect-config.json
reflect-config.json dosyası şöyle. Burada her bir eksik class teker teker tanımlanıyor
[
  {
    "name": "io.jsonwebtoken.impl.crypto.MacProvider",
    "allDeclaredConstructors": true,
    "allPublicConstructors": true,
    "allDeclaredMethods": true,
    "allPublicMethods": true,
    "allDeclaredClasses": true,
    "allPublicClasses": true
  },
  ...
]
configuration Seçenekleri

--allow-incomplete-classpath Seçeneği
reflection-config.json dosyasına her sınıfı yazdığımızı düşünsek bile halen hata almaya devam edebiliriz. Bu durumda şöyle yaparız
<buildArg>--allow-incomplete-classpath</buildArg>
Açıklaması şöyle
An alternative quick fix could be the option --allow-incomplete-classpath. This ensures that the possible linking errors are shifted from build time to run time.
--initialize-at-build-time Seçeneği
Şöyle bir hata alabiliriz. Yani bir sınıf derleme esnasında (compile time) hata veriyor
ERROR: Classes that should be initialized at run time got initialized during image building:…
Açıklaması şöyle
The most classes are initialized at build time and GraalVM tries to find out what can be initialized at build time and which classes must be initialized at run time. This error can be fixed with the parameter --initialize-at-run-time. This parameter will force to initialize this class at runtime. Another way to force to initialize a class during build is to use the parameter --initialize-at-build-time.
Örnek
Şöyle yaparız
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
  <buildArgs>
    <buildArg>--initialize-at-build-time=my.build.package</buildArg>
    <buildArg>--initialize-at-build-time=my.other.build.package.SpecificClass</buildArg>
    <buildArg>--initialize-at-run-time=my.run.package</buildArg>
    <buildArg>--initialize-at-run-time=my.other.run.package.SpecificClass</buildArg>
  </buildArgs>
</configuration>
Örnek
Şöyle yaparız
<plugin>
  <groupId>org.graalvm.buildtools</groupId>
  <artifactId>native-maven-plugin</artifactId>
  <configuration>
    <buildArgs>
      <buildArg>--initialize-at-build-time=org.apache.commons.logging.LogFactory,org.apache.commons.logging.LogFactoryService,org.slf4j.MDC,ch.qos.logback.core.pattern.parser.Parser,ch.qos.logback.core.util.Loader,ch.qos.logback.core.util.StatusPrinter,org.slf4j.impl.StaticLoggerBinder,org.slf4j.LoggerFactory,ch.qos.logback.classic.Logger,ch.qos.logback.core.spi.AppenderAttachableImpl,ch.qos.logback.core.status.StatusBase,ch.qos.logback.classic.Level,ch.qos.logback.core.status.InfoStatus,ch.qos.logback.classic.PatternLayout,ch.qos.logback.core.CoreConstants</buildArg>
      <buildArg>-H:+ReportExceptionStackTraces</buildArg>
     </buildArgs>
     <jvmArgs>
      <arg>-Xmx8g</arg>
      <arg>-Xms8g</arg>
     </jvmArgs>
  </configuration>
  <executions>
    <execution>
      <id>build-native</id>
      <goals>
        <goal>compile-no-fork</goal>
      </goals>
      <phase>package</phase>
     </execution>
    </executions>
</plugin>
jvmArgs
Örnek
Native image oluşturmak çok fazla bellek tüketiyor. Eklentinin kullanacağı belleği ayarlamak için şöyle yaparız
<plugin>
  <groupId>org.graalvm.buildtools</groupId>
  <artifactId>native-maven-plugin</artifactId>
  <configuration>
    <jvmArgs>
      <arg>-Xmx8g</arg>
      <arg>-Xms8g</arg>
     </jvmArgs>
  </configuration>
  <executions>
    <execution>
      <id>build-native</id>
      <goals>
        <goal>compile-no-fork</goal>
      </goals>
      <phase>package</phase>
    </execution>
  </executions>
</plugin>

skipNativeTests Alanı
Açıklaması şöyle
So far Mockito is not supported for tests. This can bring up problems for a high number of existing applications and result in big test refactoring projects. There are two possible ways to get it running: either exclude all mocking tests or simply skip native tests with setting the configuration skipNativeTests to true:
Örnek
Şöyle yaparız
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
    <skipNativeTests>true</skipNativeTests>
</configuration>




22 Aralık 2022 Perşembe

git-build-hook plugin

Örnek
Şöyle yaparız
<plugin>
  <groupId>com.rudikershaw.gitbuildhook</groupId>
  <artifactId>git-build-hook-maven-plugin</artifactId>
  <version>3.1.0</version>
  <configuration>
    <installHooks>
      <commit-msg>hooks/commit-msg</commit-msg>
      <pre-commit>hooks/pre-commit</pre-commit>
    </installHooks>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>install</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Projedeki hooks/pre-commit dosyası şöyle. Yani spotless plugin ile kodda düzeltmeler yapılıyor
#!/usr/bin/env bash
mvn spotless:apply
Kurmak için şöyle yaparız
mvn install



21 Aralık 2022 Çarşamba

animal-sniffer plugin

Giriş
3 tane goal sunuyor
animal-sniffer:build
animal-sniffer:check
animal-sniffer:help

Örnek
Şöyle yaparız. Java 6 ile uyumluluğu kontrol eder
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>animal-sniffer-maven-plugin</artifactId>
  <version>1.16</version>
  <configuration>
    <signature>
      <groupId>org.codehaus.mojo.signature</groupId>
      <artifactId>java16</artifactId>
      <version>1.0</version>
    </signature>
  </configuration>
  <executions>
    <execution>
      <id>animal-sniffer</id>
      <phase>verify</phase>
      <goals>
        <goal>check</goal>
       </goals>
    </execution>
  </executions>
</plugin>


20 Aralık 2022 Salı

kubernetes plugin

Goal
Eclipse JKube projesinin yarattaığı bir plugin. YAML dosyaları da oluşturabiliyor
Açıklaması şöyle
Goal Name Description
k8s:build Containerize your application into an image
k8s:push Push the Image built to a container registry
k8s:resource Generate Kubernetes Manifests
k8s:deploy Apply these manifests on top of Kubernetes
k8s:log View logs of your application running in Kubernetes Cluster
k8s:debug Debug your application running into Kubernetes
build
Docker image yapılandırır
Örnek
Şöyle yaparız
mvn k8s:build
# If docker daemon is not available mvn k8s:build -Djkube.build.strategy=jib
push
Docker image Remote Docker Repository'e gönderilir Açıklaması şöyle
To have Kubernetes Maven plugin push our built image to Docker Hub, we need to supply the image name to the Kubernetes Maven plugin, by adding jkube.generator.name property in pom.xml ...

By doing so, the Kubernetes Maven plugin will get the image name from spring-boot.build-image.imageName property.

By default, the Kubernetes Maven plugin always pushes images tagged as the latest to the remote repository. Since our built image is tagged with version rather than latest, we will need to disable this feature. Add the following jkube.skip.tag property with true value to pom.xml to disable Kubernetes Maven plugin overriding our tag in the supplied image name.
Örnek
Şöyle yaparız
<properties>
  <java.version>11</java.version>
  <spring-boot.build-image.imageName>andylke/${project.artifactId}:${project.version}</spring-boot.build-image.imageName>
  <jkube.generator.name>${spring-boot.build-image.imageName}</jkube.generator.name>
  <jkube.skip.tag>true</jkube.skip.tag>
</properties>
Şöyle yaparız
mvnw ^
  -Djkube.docker.username={docker-hub.username} ^
  -Djkube.docker.password={docker-hub.password} ^
  k8s:push
Örnek
plugin şöyle olsun
<plugin>
  <groupId>org.eclipse.jkube</groupId>
  <artifactId>kubernetes-maven-plugin</artifactId>
  <version>${jkube.version}</version>
  <configuration>
    <images>
      <image>
        <name>quay.io/rohankanojia/helloapp:${project.version}</name>
        <alias>hello-world</alias>
        <build>
          <from>openjdk:latest</from>
          <cmd>java -jar maven/${project.artifactId}-${project.version}.jar</cmd>
        </build>
      </image>
   </images>
  </configuration>
</plugin>
Şöyle yaparız
mvn k8s:push

mvn k8s:push -Djkube.build.strategy=jib
resource
Açıklaması şöyle
Kubernetes Maven plugin can either generate 
1. based on opinionated defaults, 
2. based on the configuration provided in XML config
3. resource templates in src/main/jkube directory.
Açıklaması şöyle
By default, Kubernetes Maven plugin generates a Deployment with a single replica and Service resource that is only reachable from within the cluster, known as ClusterIP. To create a network load balancer service with an externally accessible IP address, we need to change the default Service type to LoadBalancer. Add a jkube.enricher.jkube-service.type property with value LoadBalancer as follows.
<jkube.enricher.jkube-service.type>LoadBalancer</jkube.enricher.jkube-service.type>

Run the following command to invoke the Kubernetes Maven plugin to generate Kubernetes manifests.

mvnw k8s:resource
Açıklaması şöyle
These Kubernetes manifests are all generated in target/classes/META-INF/jkube/kubernetes directory. You should find your generated jkube-app-deployment.yml and jkube-app-service.yml files

Örnek
Şöyle yaparız. Kubernetes yaml dosyalarını oluşturur
mvn k8s:resource
apply
Açıklaması şöyle
Kubernetes Maven plugin will combine all generated Kubernetes manifests from the target/classes/META-INF/jkube/kubernetes directory into a single Kubernetes manifest file, target/classes/META-INF/jkube/kubernetes.yml. This consolidated Kubernetes manifest will be used when we invoke the apply goal in Kubernetes Maven plugin.

Run the following command to apply our generated Kubernetes manifest to our locally connected Kubernetes cluster.

mvnw k8s:apply

Your Kubernetes manifest being applied successfully to the Kubernetes cluster does not guarantee the defined Kubernetes resources will start successfully. Always verify the state of your applied resources.

Run the following command to list all resources in your local Kubernetes cluster with labels app=jkube-app.

kubectl get all -l app=jkube-app

If all goes well, you should have a running Pod, a service with an external IP address, a deployment, and ReplicaSet.
deploy
Şöyle yaparız. Kubernetes'te çalıştırır
mvn k8s:deploy

mvn k8s:undeploy

# Inspect logs
mvn k8s:log
mvn k8s:log -Djkube.log.follow=false
debug
Şöyle yaparız. Kubernetes'te debug için çalıştırır
mvn k8s:debug

mvn k8s:debug -Djkube.debug.port=8000
remote-dev
Örnek
plugin şöyle olsun
<plugin>
  <groupId>org.eclipse.jkube</groupId>
  <artifactId>kubernetes-maven-plugin</artifactId>
  <version>${jkube.version}</version>
  <configuration>
    <remoteDevelopment>
      <remoteServices>
        <remoteService>
          <hostname>service1</hostname> <!-- Name of Service -->
          <port>8080</port>                 <!-- Service port -->
          <localPort>8081</localPort>       <!-- Local Port where to expose -->
        </remoteService>
        <remoteService>
          <hostname>service2</hostname>  <!-- Name of Service -->
          <port>8080</port>           <!-- Service Port -->
          <localPort>8082</localPort> <!-- Local Port where to expose -->
        </remoteService>
      </remoteServices>
    </remoteDevelopment>
  </configuration>
</plugin>
Şöyle yaparız. Böylece kubernetes ortamında çalışan 2 tane service deploy edilir. Servisler localhost 8081 ve 8082 portları ile erişilebilir
mvn k8s:remote-dev


16 Aralık 2022 Cuma

kafka-schema-registry plugin - Avro Schema'larını Schema Registry Sunucusuna Kaydeder

Örnek
Şöyle yaparız
<plugin>
  <groupId>io.confluent</groupId>
  <artifactId>kafka-schema-registry-maven-plugin</artifactId>
  <version>${confluent.version}</version>
  <configuration>
     <schemaRegistryUrls>
        <param>http://localhost:8081</param>
     </schemaRegistryUrls>
     <subjects>
        <send-payment-value>${project.basedir}/src/main/resources/avro/send_payment.avsc</send-payment-value>
        <payment-sent-value>${project.basedir}/src/main/resources/avro/payment_sent.avsc</payment-sent-value>
     </subjects>
  </configuration>
  <goals>
     <goal>register</goal>
  </goals>
</plugin>
acro dizininde Şöyle yaparız
mvn schema-registry:register


mvnup komutu

check Şöyle yaparız mvnup check apply Şöyle yaparız mvnup apply