17 Temmuz 2023 Pazartesi

shade plugin - relocation Kullanımı

Giriş
Bazen bir kütüphane ile gelen 3. taraf bağımlılıklar ile kendi projem arasında uyumsuzluk olur.  

1. relocation Alanı
relocation ve shadedPattern genelde birlikte kullanılır

Örnek
Şöyle yaparız. Burada org.apache.calcite kodları başka bir dizinine toplanır
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <configuration>
    <shadedArtifactAttached>false</shadedArtifactAttached>
    <relocations>
      <relocation>
        <pattern>org.apache.calcite</pattern>
        <shadedPattern>${relocation.root}.org.apache.calcite</shadedPattern>
      </relocation>
    </relocations>
  </configuration>
</plugin>
Örnek
Şöyle yaparız
- Burada joda-time ve com.amazonaws kütüphanelerini dahil eden bir fat jar üretiliyor. 
- Ayrıca org.joda paketleri com.amazonaws.thirdparty.joda altına taşınıyor.
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.4.3</version>
  <configuration>
    <artifactSet>
      <includes>
        <include>joda-time:joda-time</include>
        <include>com.amazonaws:*</include>
      </includes>
    </artifactSet>
    <relocations>
      <relocation>
        <pattern>org.joda</pattern>
        <shadedPattern>com.amazonaws.thirdparty.joda</shadedPattern>
      </relocation>
    </relocations>
  </configuration>
</plugin>
Örnek
Şöyle yaparız
<plugin>
  <artifactId>maven-shade-plugin</artifactId>
  <configuration>

    <!-- Cancel the relocation of jackson-core defined in parent pom.
    <relocations combine.self="override">
    </relocations>
  </configuration>
</plugin>
veya şöyle yaparız
<plugin>
  <artifactId>maven-shade-plugin</artifactId>
  <configuration>

    <!-- Cancel the relocation of jackson-core defined in hazelcast-parent pom.
    <relocations combine.self="override">
      <relocation>
        <pattern>com.fasterxml.jackson.core</pattern>
        <shadedPattern>com.fasterxml.jackson.core</shadedPattern>
      </relocation>
    </relocations>
  </configuration>
</plugin>
2. Sadece shadedPattern Alanı
Açıklaması şöyle. Kendi kodlarım ve dependency olarak gelen kütüphaneler shade isimli bir dizine toplanır. İstenirse bu dizine yeni bir isim verilebilir
The "shadedPattern" is a configuration option in the Maven Shade Plugin that specifies the pattern for renaming the classes and resources in the shaded JAR file.

When you use the Maven Shade Plugin to create a shaded JAR, it merges all the dependencies of your project into a single JAR file. During the shading process, the plugin renames the classes and resources from the original JAR files to avoid conflicts with other libraries in the classpath.

The shadedPattern option allows you to specify the pattern for the renamed classes and resources in the shaded JAR. By default, the pattern is "shade/[class]", which means that all classes and resources will be moved to a "shade" directory in the JAR file.

You can customize the shadedPattern option to change the directory structure or add prefixes or suffixes to the renamed classes and resources. For example, you could use the pattern "myapp/[artifactId]-[version]/[class]" to create a directory structure that includes the name and version of your project.
Örnek
Şöyle yaparız. Burada kendi kodlarım da dahil olmak üzere her şey myapp/my-app-1.0.0/ dizinine toplanır
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.2.4</version>
  <configuration>
    <shadedPattern>myapp/[artifactId]-[version]/[class]</shadedPattern>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Hiç yorum yok:

Yorum Gönder

Local Snapshot Kullanmak

Örnek Şöyle yaparız <repository> <id>snapshot-repository</id> <name>Maven2 Snapshot Repository</name> &l...