set maven property during build process

19 views Asked by At

I need to create fat jar of mongo-kafka-connect and save it to some directory, lets say jars mongo-connect.jar so that I can copy it into image using Dockerfile. I did this using maven shade plugin like this:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>${shade.plugin.version}</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>org.mongodb.kafka:mongo-kafka-connect</artifact>
                            <includes>
                                <include>**/*</include>
                            </includes>
                        </filter>
                    </filters>
                    <finalName>mongo-kafka-connect-fat-${mongo.connector.version}</finalName>
                    <outputDirectory>connector-jars</outputDirectory>
                    <shadedArtifactAttached>false</shadedArtifactAttached>
                </configuration>
            </execution>
        </executions>
    </plugin>

but I dont want to download this files each time I am building project so I want to check if this file already exists and only if it is not I want to run shade plugin. And so I have added

    <configuration>
        <skip>${jar.exists}</skip>
        <createDependencyReducedPom>false</createDependencyReducedPom>

this skip. Now I do not know how to set this jar.exists depending if the file exists or not. Or maybe someone have got better idea how to achieve this? I am quite new to maven :(

I tried something like this


    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>check-jar-existence</id>
                <phase>validate</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <target>
                        <!-- Use ANT's available task to check if file exists -->
                        <available
                                file="/connector-jars/mongo-kafka-connect-fat-1.11.0.jar"
                                property="jar.exists" value="true"/>
                    </target>
                </configuration>
            </execution>
        </executions>
    </plugin>

but as you could guess it did not work also added this

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <phase>initialize</phase> <!-- Choose the appropriate phase -->
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>echo</executable>
                    <arguments>
                        <argument>jar.exists value: ${jar.exists}</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>

to print the value to the console. The output is jar.exists value: ${jar.exists} so the property is not initialized at all

0

There are 0 answers