2

I have a multimodule scala maven project with below hierarchy:

MyProject:
|
----pom.xml -------> Parent pom
---Module 1
    |
    --------------pom.xml --> Child pom 1
    --------------src/main/scala
    --------------src/test
----Module 2
    |
    ---------pom.xml --> Child pom 2

the pom.xml of parent has below <pluginManagement> Tag

    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>4.5.6</version>
                    <executions>
                        <execution>
                            <id>scala-compile-first</id>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>add-source</goal>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>net.revelc.code.formatter</groupId>
                    <artifactId>formatter-maven-plugin</artifactId>
                    <version>10.0.0</version>
                    <configuration>
                        <configFile>${formatter.url}</configFile>
                        <encoding>UTF-8</encoding>
                        <includes>
                            <include>**/*.scala</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>format</id>
                            <phase>process-sources</phase>
                            <goals>
                                <goal>format</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco-maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>

The Child module has below pom.xml with <profile> tag:

<profiles>
        <profile>
            <id>appplication</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>net.alchim31.maven</groupId>
                            <artifactId>scala-maven-plugin</artifactId>
                            <version>4.5.6</version>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-shade-plugin</artifactId>
                            <version>${maven-shade-plugin.version}</version>
                            <configuration>
                                <filters>
                                    <filter>
                                        <artifact>*:*</artifact>
                                        <excludes>
                                            <exclude>META-INF/*.SF</exclude>
                                            <exclude>META-INF/*.DSA</exclude>
                                            <exclude>META-INF/*.RSA</exclude>
                                        </excludes>
                                    </filter>
                                </filters>
                            </configuration>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>shade</goal>
                                    </goals>
                                    <configuration>

                                        <shadedArtifactAttached>true</shadedArtifactAttached>
                                        <shadedClassifierName>platform</shadedClassifierName>
                                        <artifactSet>
                                            <excludes>
                                                <exclude>org.apache.flink:force-shading</exclude>
                                                <exclude>com.google.code.findbugs:jsr305</exclude>
                                                <exclude>org.slf4j:*</exclude>
                                                <exclude>log4j:*</exclude>
                                            </excludes>
                                        </artifactSet>
                                        <transformers>
                                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                                <resource>reference.conf</resource>
                                            </transformer>
                                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                                <mainClass>com.exampleMainClass</mainClass>
                                            </transformer>
                                        </transformers>
                                        <relocations>
                                            <relocation>
                                                <pattern>com.google.protobuf</pattern>
                                                <shadedPattern>shaded.com.google.protobuf</shadedPattern>
                                            </relocation>
                                        </relocations>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-assembly-plugin</artifactId>
                            <version>2.4</version>
                            <executions>
                                <execution>
                                    <id>make-assembly</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>attached</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <tarLongFileMode>gnu</tarLongFileMode>
                                <descriptorRefs>
                                    <descriptorRef>jar-with-dependencies</descriptorRef>
                                </descriptorRefs>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>

                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <configuration>
                            <classpathScope>runtime</classpathScope>
                        </configuration>
                        <version>${exec-maven-plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>${maven-shade-plugin.version}</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.4</version>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

When I run mvn package OR mvn clean install the fat jar does gets created with all the dependencies, but the actual scala classes are not included in the JAR. They only get complied and stay in the classes folder under respective target folder of its Module.

I am able to get the scala classes in using the assembly plugin but I need to use the maven shaded plugin as there are a few classes which does coincide in the dependencies.

0 Answers0