26 Ekim 2022 Çarşamba

developers tag

Giriş
Bu tag bence çok gereksiz bir şey ama bazı projelerde kullanılıyor

Örnek
Şöyle yaparız
<!-- List the core committers -->
<developers>
  <developer>
    <id>karianna</id>
    <name>Martijn Verburg</name>
    <organization>Ikasan</organization>
     <organizationUrl>http://www.ikasan.org</organizationUrl>
      <roles>
        <role>developer</role>
      </roles>
    <timezone>0</timezone>
  </developer>
  ...
</developers>

<!-- Contributors -->
<contributors>
  <contributor>
    <name>Cae Fernandes</name>
    <roles>
      <role>developer</role>
    </roles>
    <timezone>-3</timezone>
  </contributor>
  ...
</contributors>



19 Ekim 2022 Çarşamba

Dependency Management with BOM

Giriş
Açıklaması şöyle
BOM stands for "Bill Of Materials". A BOM is a special kind of POM that is used to control the versions of a project’s dependencies and provide a central place to define and update those versions.
Açıklaması şöyle
The Bill Of Material is a special POM file that groups dependency versions that are known to be valid and tested to work together. This will reduce the developers’ pain of having to test the compatibility of different versions and reduce the chances to have version mismatches.
1. BOM Yazmak
Açıklaması şöyle
BOM elements:

1. a pom packaging type: <packaging>pom</packaging>.
2. a dependencyManagement the section that lists the dependencies of a project.
Inside the dependencyManagement we will set all of the dependencies needed and specific versions of the dependency because it is mandatory.
Örnek
Şöyle yaparız
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>reflectoring</groupId>
  <artifactId>reflectoring-bom</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <name>Reflectoring Bill Of Material</name>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.reflectoring</groupId>
        <artifactId>logging</artifactId>
        <version>2.1</version>
      </dependency>
      <dependency>
        <groupId>io.reflectoring</groupId>
        <artifactId>test</artifactId>
        <version>1.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>
2. BOM'u Kullanmak
İki yöntem var.
1.BOM As A Parent Yöntemi
2.BOM as a Dependency Yöntemi

2.1 BOM As A Parent Yöntemi
Bir projede tek bir parent BOM olabilir. <parent>...</parent> tagleri içine yazılır
Örnek
Şöyle yaparız
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>baeldung</groupId>
  <artifactId>Test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>Test</name>
  <parent>
    <groupId>baeldung</groupId>
    <artifactId>Baeldung-BOM</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
</project>
Örnek
Şöyle yaparız
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>reflectoring</groupId>
    <artifactId>reflectoring-bom</artifactId>
    <version>1.0</version>
  </parent>
    
  <groupId>reflectoring</groupId>
  <artifactId>new-project</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>New Project</name>
    
  <dependency>
    <groupId>io.reflectoring</groupId>
    <artifactId>logging</artifactId>
  </dependency>
</project>

2.2 BOM as a Dependency
Bir projede tek bir parent BOM olabilir, ancak bazen bir başka projeden de parent BOM gelebiliyor. Bu durumda BOM kendi pom.xml dosyamıza <dependencyManagement>..</dependencyManagement> olarak kopyalanabilir. Kullanırken şöyle yaparız
<type>pom</type>
<scope>import</scope>
Örnek
Şöyle yaparız. Burada SpringBoot Starter Parent projesini Bill Of Materials olarak kullandık
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>2.5.4</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
Örnek
Şöyle yaparız
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>baeldung</groupId>
  <artifactId>Test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>Test</name>
    
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>baeldung</groupId>
        <artifactId>Baeldung-BOM</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>
Örnek
Şöyle yaparız
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>reflectoring</groupId>
  <artifactId>new-project</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>New Project</name>
    
  <dependency>
    <groupId>io.reflectoring</groupId>
    <artifactId>logging</artifactId>
  </dependency>
    
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>reflectoring</groupId>
        <artifactId>reflectoring-bom</artifactId>
        <version>1.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

11 Ekim 2022 Salı

xolstice protobuf plugin

Giriş
protobuf için birkaç tane plugin var. Sanırım en çok kullanılanı bu. 

Goals
Şöyle
compile
compile-custom

Her iki goal da kullanılmalı

Ayarlar
Bu kısımlar her zaman şöyle

Ortak Ayarlar
protocArtifact : com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}

compile Ayarları
pluginId : grpc-java

compile-custom Ayarları
pluginArtifact : io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}


protoSourceRoot alanını belirtilmemişse src/main/proto altındaki "*.proto" dosyalarını işler

Ayrıca şu dependency de lazım
<dependency>
<groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.12.2</version> </dependency>
Bu plugini kullanabilmek için şu lazım
<build>
  <!-- protobuf extension-->
  <extensions>
    <extension>
      <groupId>kr.motd.maven</groupId>
      <artifactId>os-maven-plugin</artifactId>
      <version>1.7.1</version>
    </extension>
  </extensions>
...
</build>
compile goal
Tam hali şöyle
<build>
  <extensions>
    <extension>
      <groupId>kr.motd.maven</groupId>                   
      <artifactId>os-maven-plugin</artifactId>
      <version>1.7.1</version>
    </extension>
  </extensions>
  <plugins>
    <plugin>
      <groupId>org.xolstice.maven.plugins</groupId>      
      <artifactId>protobuf-maven-plugin</artifactId>
      <version>${protobuf-plugin.version}</version>
      <configuration>
        <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
        <pluginId>grpc-java</pluginId>
        <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>compile</goal>
            <goal>compile-custom</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Örnek
Şöyle yaparız
<plugin>
  <groupId>org.xolstice.maven.plugins</groupId>
  <artifactId>protobuf-maven-plugin</artifactId>
  <version>0.6.1</version>
  <configuration>
    <protocArtifact>
      com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier}
    </protocArtifact>
    <pluginId>grpc-java</pluginId>
    <pluginArtifact>
      io.grpc:protoc-gen-grpc-java:1.52.1:exe:${os.detected.classifier}
    </pluginArtifact>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>compile-custom</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Örnek
Şöyle yaparız
<plugin>
  <groupId>org.xolstice.maven.plugins</groupId>
  <artifactId>protobuf-maven-plugin</artifactId>
  <version>0.5.1</version>
  <configuration>
    <protocArtifact>
      com.google.protobuf:protoc:3.6.1:exe:${os.detected.classifier}
    </protocArtifact>
    <pluginId>grpc-java</pluginId>
    <pluginArtifact>
      io.grpc:protoc-gen-grpc-java:1.22.1:exe:${os.detected.classifier}
    </pluginArtifact>
    <protoSourceRoot>
      ${basedir}/src/main/proto/
    </protoSourceRoot>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>compile-custom</goal>
      </goals>
    </execution>
  </executions>
</plugin>
compile-custom Goal


Örnek
proto dosyalarından dokümantasyon üretmek için şu eklentiler kullanılabilir. 
protoc-gen-doc
gRPC-docs
GenDocu Cloud
Buf

protoc-gen-doc kullanmak için şöyle yaparız. Burada hem compile hem de compile-custom goal belirtiliyor. Ancak compile-custom iki defa belirtiliyor. İkinci belirtimde  protoc-gen-doc plugin kullanılarak dokümantasyon üretmesi isteniyor

<plugin>
  <groupId>org.xolstice.maven.plugins</groupId>
  <artifactId>protobuf-maven-plugin</artifactId>
  <version>0.6.1</version>
  <configuration>
    <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
    </protocArtifact>
  </configuration>
  <executions>
    <execution>
      <id>protoc-java</id>
      <goals>
       <goal>compile</goal>
      </goals>
     </execution>
     <execution>
      <id>protoc-grpc</id>
      <goals>
       <goal>compile-custom</goal>
      </goals>
      <configuration>
       <pluginId>grpc-java</pluginId>
       <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
       </pluginArtifact>
      </configuration>
     </execution>
     <execution>
      <id>protoc-doc</id>
      <goals>
       <goal>compile-custom</goal>
      </goals>
      <configuration>
       <pluginId>doc</pluginId>
       <pluginArtifact>
        io.github.pseudomuto:protoc-gen-doc:${protoc-gen-doc.version}:exe:${os.detected.classifier}
       </pluginArtifact>
       <pluginParameter>markdown,grpc-api.md</pluginParameter>
      </configuration>
     </execution>
    </executions>
   </plugin>

  </plugins>
 </build>






settings.xml Dosyası

Giriş
Dosyanın yolu şöyle
~/.m2/settings.xml
Türkçe Windows'ta yol şöyle
C:\Users\user\.m2
Örnek - Boş Dosya
Şöyle yaparız
<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

Örnek
Properties vermek için şöyle yaparız
<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers/>
  <profiles>
    <profile>
      <id>default</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        ...
      </properties>
    </profile>
  </profiles>
</settings>



7 Ekim 2022 Cuma

help plugin

Giriş
Açıklaması şöyle
The effective pom is the POM that results from the application of interpolation, inheritance and active profiles. To generate the effective POM, run the following command in your terminal: ./mvnw help:effective-pom.

When running this command on the the example project, the result will be fairly small, because it is a relatively small project. For a large project, the effective pom will be much bigger. If needed, you can write the effective POM into a log file using the following command: ./mvnw help:effective-pom --log-file log.txt.
Örnek
Şöyle yaparız
mvn help:effective-pom -Doutput=effective-pom.xml

16 Eylül 2022 Cuma

jaxb2 plugin

Örnek
Şöyle yaparız
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <id>xjc</id>
      <goals>
        <goal>xjc</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
    <clearOutputDir>false</clearOutputDir>
  </configuration>
</plugin>
XSD dosyasını "src/main/resources" altına yerleştiririz. "mvn install" yaparız

8 Eylül 2022 Perşembe

Maven Helper IntelliJ Plugin

Giriş
Açıklaması şöyle. Plugin burada
Maven Helper, by Vojtch Krassa, is used for debugging and maintaining projects with many modules. Developers are often faced with conflicts and dependencies that are difficult to manage as the project size and the code repo increases. This plug-in provides easy options to navigate dependencies in code and eliminate conflicts.

Maven Helper consists of actions that can run and debug Maven goals, open a terminal to the current module path, and run and debug test files. It’s one of the most popular plug-ins in the tech industry and is very easy to use. For instance, with the click of a button you can predefine and run Maven goals.
pom.xml dosyası açılır ve plugin ile gelen "Dependency Analyzer" sekmesine gidilir. Conflicts seçeneği seçilir ve kırmızı renk ile gösterilen ve conflict (uyumsuz) jar'lara bakılır. Şeklen şöyle



mvnup komutu

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