Skip to content

Latest commit

 

History

History
175 lines (162 loc) · 6.9 KB

maven.md

File metadata and controls

175 lines (162 loc) · 6.9 KB

Maven tricks

Filtering resources

um im properties dateien Variablen durch maven ersetzten zu lassen , kann man :

<build>
		<resources>
			<!-- https://stackoverflow.com/questions/3697449/retrieve-version-from-maven-pom-xml-in-code/41791885 
				https://stackoverflow.com/questions/38983934/cannot-get-maven-project-version-property-in-a-spring-application-with-value -->
			<resource>
				<filtering>true</filtering>
				<directory>src/main/resources</directory>
				<includes>
					<include>build.properties</include>
				</includes>
			</resource>
			<resource>
				<filtering>false</filtering>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/*</include>
					<include>*</include>
				</includes>
				<excludes>
            <exclude>build.properties</exclude>
        </excludes>
			</resource>
		</resources>
...

How to add Jacoco for coverage and make it to include unit AND integration tests for the coverage reports

The only thing you have to make sure is, that the report is generated after the integration-test phase. Because by default the Jacoco report is run before the integration-test phase.

Surprisingly enough, this:

<plugin>
	<groupId>org.jacoco</groupId>
	<artifactId>jacoco-maven-plugin</artifactId>
	<version>0.8.10</version>
	<executions>
		<execution>
			<id>jacoco-prepare-agent</id>
			<goals>
				<goal>prepare-agent</goal>
			</goals>
		</execution>
		<execution>
			<id>jacoco-report</id>
			<!-- needed in order to make the report also include the results from the integration tests -->
			<phase>post-integration-test</phase>
			<goals>
				<goal>report</goal>
			</goals>
		</execution>
	</executions>
</plugin>

already adds the additional necessary command line parameters for coverage measuring not only to the unit-tests but also to the integration-tests. But since the report is generated by default before integration-tests their coverage is not included in the test by default.

So just adding this:

<execution>
	<id>jacoco-report</id>
	<!-- needed in order to make the report also include the results from the integration tests -->
	<phase>post-integration-test</phase>
	<goals>
		<goal>report</goal>
	</goals>
</execution>

is already sufficient to add the integration-tests coverage to the report.

All the claims on the internet, and in chatGPT for a much more complicated configuration using Jacocos merge goal or defining <argLine>${argLine}</argLine> for surefire-plugin or <argLine>${failsafe.argLine}</argLine> for the fail-safe-plugin is not necessary at all!

openapi generate sources:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.6.1</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>xxx.myxxx.notification</groupId>
                                    <artifactId>myxxx-notification-service-contracts</artifactId>
                                    <version>${myxxx-notification-service-contracts.version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/openapi-specs</outputDirectory>
                                    <includes>*.yml</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

...

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <id>adp</id>
                        <configuration>
                            <inputSpec>
                                ${project.build.directory}/openapi-specs/myxxx-notification-app-definition-openapi.yml
                            </inputSpec>
                            <generatorName>spring</generatorName>
                            <library>spring-boot</library>
                            <modelNameSuffix>Dto</modelNameSuffix>
                            <invokerPackage>xxx.myapp.myxxx.gen.rest.notification.api</invokerPackage>
                            <apiPackage>xxx.myapp.myxxx.gen.rest.notification.api</apiPackage>
                            <modelPackage>xxx.myapp.myxxx.gen.rest.notification.api</modelPackage>
                            <skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
                            <configOptions>
                                <useJakartaEe>true</useJakartaEe>
                                <interfaceOnly>true</interfaceOnly>
                                <useTags>true</useTags>
                                <openApiNullable>false</openApiNullable>
                                <useSpringBoot3>true</useSpringBoot3>
                                <documentationProvider>none</documentationProvider>
                            </configOptions>
                        </configuration>
                    </execution>
                   </executions>
             </plugin>

doppelte "junit-platform.properties warnung

sometimes you get a warning

Okt. 08, 2024 8:42:07 AM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
WARNUNG: Discovered 2 'junit-platform.properties' configuration files in the classpath; only the first will be used.
Okt. 08, 2024 8:42:07 AM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
WARNUNG: Discovered 2 'junit-platform.properties' configuration files in the classpath; only the first will be used.

suche mit :

#!/bin/bash
# Find all JAR files in the local Maven repository that contain junit-platform.properties
cd ~/.m2  # Change to the local Maven repository
# List all JAR files in the classpath
for jar in $(find . -name "*.jar"); do
  echo look into $jar
  # Check if the JAR file contains junit-platform.properties
  if jar tf "$jar" | grep -q "junit-platform.properties"; then
    echo "Found in: $jar"
  fi
done

# result e.g. :
# ./repository/org/apache/kafka/kafka-clients/3.7.1/kafka-clients-3.7.1-test.jar
# and
# ./repository/org/apache/kafka/kafka-server-common/3.7.1/kafka-server-common-3.7.1-test.jar