Added "Check for Updates" documentation and Fatjar profile

This commit is contained in:
Konrad Neitzel 2024-05-27 14:28:14 +02:00
parent ef4fedd441
commit 09851cde11
6 changed files with 239 additions and 3 deletions

View File

@ -2,12 +2,15 @@
Example Maven Project for a JavaFX Application. Example Maven Project for a JavaFX Application.
**Update**: Added profile fatjar
**Update**: Added reporting to create a site (html documentation of project) **Update**: Added reporting to create a site (html documentation of project)
**Update**: Java 21 is now fully supported **Update**: Java 21 is now fully supported
This projects includes multiple plugins: This projects includes multiple plugins:
- Build of an App-Image using JPackage - Build of an App-Image using JPackage (Profile: image)
- Build of an fat jar (Profile: fatjar)
- Use of Maven Wrapper - Use of Maven Wrapper
- Static code analysis with PMD and Spotbugs - Static code analysis with PMD and Spotbugs
- Check of dependency updates during build - Check of dependency updates during build

View File

@ -0,0 +1,103 @@
# Überprüfung auf Updates
Eine regelmäßige Überprüfung auf Updates von Plugins und Dependencies ist aus mehreren Gründen essenziell für die
Softwareentwicklung. Erstens garantiert sie Sicherheit, indem sie sicherstellt, dass alle verwendeten Komponenten auf
dem neuesten Stand sind und bekannte Sicherheitslücken geschlossen werden. Zweitens verbessert sie die Leistung und
Stabilität der Software, da Updates oft Optimierungen und Fehlerbehebungen enthalten. Drittens ermöglicht die
Aktualisierung den Zugang zu neuen Funktionen und Technologien, was die Entwicklung effizienter und zukunftssicher
macht. Durch das regelmäßige Aktualisieren wird zudem die Kompatibilität mit anderen Tools und Systemen sichergestellt,
was die Integration und Wartung vereinfacht.
## Codehaus Version Plugin
Das Codehaus Versions Maven Plugin ist ein nützliches Werkzeug in der Softwareentwicklung, da es überprüft, ob neuere
Versionen von Plugins oder Dependencies verfügbar sind. Es hilft Entwicklern, ihre Projekte auf dem neuesten Stand zu
halten, indem es automatisch nach Updates sucht und Vorschläge für mögliche Upgrades macht. Diese Funktionalität ist
besonders wichtig, um sicherzustellen, dass die verwendeten Komponenten aktuell sind und um von den neuesten
Sicherheitspatches, Fehlerbehebungen und Leistungsverbesserungen zu profitieren. Das Plugin bietet eine einfache und
effiziente Möglichkeit, die Softwarewartung zu optimieren und die Softwarequalität zu verbessern.
## Einbindung in das Projekt
Das Plugin ist sehr einfach in ein Projekt einbindbar:
```xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${codehaus.version.plugin}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
<goal>display-property-updates</goal>
</goals>
</execution>
</executions>
</plugin>
```
Wichtig ist, dass die Ziele sowohl für Abhängigkeiten, Plugins als auch Properties ausgeführt wird, damit kein Update
übersehen wird.
## Probleme
Die Verfügbarkeit von Updates für Plugins und Dependencies in einem Maven-Projekt kann teilweise von der verwendeten
Version von Maven selbst abhängen. Neuere Versionen von Maven unterstützen oft aktuellere Plugins und Dependencies,
die verbesserte Funktionen und Sicherheitsupdates bieten können. Daher ist es wichtig, sicherzustellen, dass ein
Projekt mit einer spezifischen, minimal erforderlichen Maven-Version betrieben wird.
Um dies zu gewährleisten, kann das Maven Enforcer Plugin eingesetzt werden. Dieses Plugin erlaubt es, bestimmte Regeln
innerhalb der Build-Umgebung durchzusetzen, darunter auch die Anforderung einer minimalen Maven-Version. Durch die
Konfiguration des Maven Enforcer Plugins im Build-Prozess wird sichergestellt, dass der Build nur dann erfolgreich
durchgeführt wird, wenn die verwendete Maven-Version der definierten Mindestanforderung entspricht. Dies hilft,
Inkonsistenzen und potenzielle Fehler aufgrund von Versionskonflikten zu vermeiden und fördert die Stabilität und
Sicherheit des Projekts.
Einbindung des Maven Enforcer Plugins:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.enforcer.plugin}</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${required.maven.version}</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
```
## Ergebnis
Während des Build-Vorgangens bekommt man eine Ausgabe ähnlich:
```text
[INFO] The following version properties are referencing the newest available version:
[INFO] ${codehaus.version.plugin} ................................... 2.16.2
[INFO] ${javafx.maven.plugin} ........................................ 0.0.8
[INFO] The following version property updates are available:
[INFO] ${javafx.version} ................................. 21.0.3 -> 23-ea+3
[INFO] ${junit.version} ................................ 5.10.2 -> 5.11.0-M1
[INFO] ${maven.site.plugin} ......................... 4.0.0-M13 -> 4.0.0-M14
```
**Hinweis** Das Tool führt keine Bewertung der Updates durch. So zeigt die kopierte Ausgabe drei mögliche
Aktualisierungen:
- javafx.version könnte auf eine early access Version aktualisiert werden. Das ist etwas, das man sich natürlich gut
überlegen sollte (und bei JavaFX kann es sinnvoll sein, die Main-Version gleich zur Java Version zu halten).
- Für JUnit gibt es eine neue Milestone Version. Auch hier kann es Sinn machen, keine Milestone Versionen zu verwenden.
- Für das Site Version wird bereits auf eine Milestone Version gesetzt. Hier macht das Update dann durchaus Sinn.
**Es wird also deutlich, dass hier eine bewusste Bewertung stattfindet, die vom Plugin nicht geleistet werden kann.**

View File

@ -5,7 +5,7 @@
## Maven Projekt ## Maven Projekt
- [Übersicht über das Maven Projekt](MavenProject.md) - [Übersicht über das Maven Projekt](MavenProject.md)
- [Erzeugung eines Images](ImageCreation.md) - [Erzeugung eines Images](ImageCreation.md)
- Überprüfung auf Aktualisierungen - [Überprüfung auf Updates](CheckUpdates.md)
## [Statische Codeanalyse](StaticCodeAnalysis.md) ## [Statische Codeanalyse](StaticCodeAnalysis.md)
- [PMD](PMD.md) - [PMD](PMD.md)

View File

@ -0,0 +1,75 @@
# Checking for Updates
Regular updates of plugins and dependencies are crucial for software development for several reasons. First, they
ensure security by keeping all components up-to-date and closing known vulnerabilities. Second, updates often include
optimizations and bug fixes, which improve the performance and stability of the software. Third, updating allows access
to new features and technologies, making development more efficient and future-proof. Regular updates also ensure
compatibility with other tools and systems, simplifying integration and maintenance.
## Codehaus version plugin
The Codehaus Versions Maven Plugin is a valuable tool in software development, as it checks for newer versions of
plugins or dependencies. It assists developers in keeping their projects up-to-date by automatically searching for
updates and suggesting possible upgrades. This functionality is especially important to ensure that the components
used are current and to benefit from the latest security patches, bug fixes, and performance improvements. The plugin
offers a simple and efficient way to optimize software maintenance and enhance software quality.
## Inclusion in project
The plugin can easily be added to the maven project:
```xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${codehaus.version.plugin}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
<goal>display-property-updates</goal>
</goals>
</execution>
</executions>
</plugin>
```
It is important, that we start the goals to display updates for dependencies, plugins and also properties.
## Problems
The availability of updates for plugins and dependencies in a Maven project can sometimes depend on the version of
Maven being used. Newer versions of Maven often support more current plugins and dependencies, which can offer improved
features and security updates. Therefore, it is important to ensure that a project is operated with a specific, minimum
required version of Maven.
To enforce this, the Maven Enforcer Plugin can be utilized. This plugin allows specific rules to be enforced within
the build environment, including the requirement for a minimum Maven version. By configuring the Maven Enforcer Plugin
in the build process, it is ensured that the build only proceeds successfully if the Maven version used meets the
defined minimum requirement. This helps to avoid inconsistencies and potential errors due to version conflicts,
promoting the stability and security of the project.
Inclusion of the maven enforcer plugin:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.enforcer.plugin}</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${required.maven.version}</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
```

View File

@ -5,7 +5,7 @@
## Maven Project ## Maven Project
- [Maven Project Overview](MavenProject.md) - [Maven Project Overview](MavenProject.md)
- [Image Creation](ImageCreation.md) - [Image Creation](ImageCreation.md)
- Checking of Updates - [Checking for Updates](CheckUpdates.md)
## [Static Code Analysis](StaticCodeAnalysis.md) ## [Static Code Analysis](StaticCodeAnalysis.md)
- [PMD](PMD.md) - [PMD](PMD.md)

55
pom.xml
View File

@ -43,6 +43,7 @@
<maven.javadoc.plugin>3.6.3</maven.javadoc.plugin> <maven.javadoc.plugin>3.6.3</maven.javadoc.plugin>
<maven.project.info.reports.plugin>3.5.0</maven.project.info.reports.plugin> <maven.project.info.reports.plugin>3.5.0</maven.project.info.reports.plugin>
<maven.resources.plugin>3.3.1</maven.resources.plugin> <maven.resources.plugin>3.3.1</maven.resources.plugin>
<maven.shade.plugin>3.5.3</maven.shade.plugin>
<maven.site.plugin>4.0.0-M14</maven.site.plugin> <maven.site.plugin>4.0.0-M14</maven.site.plugin>
<maven.surfire.plugin>3.2.5</maven.surfire.plugin> <maven.surfire.plugin>3.2.5</maven.surfire.plugin>
<moditect.maven.plugin>1.0.0.RC2</moditect.maven.plugin> <moditect.maven.plugin>1.0.0.RC2</moditect.maven.plugin>
@ -465,5 +466,59 @@
</build> </build>
</profile> </profile>
<!-- Profile to build a fat jar
Add -Pfatjar or -Dfatjar to use this profile.
-->
<profile>
<id>fatjar</id>
<activation>
<property>
<name>fatjar</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.plugin}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>full</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${main.class}</Main-Class>
<Build-Version>1.0</Build-Version>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles> </profiles>
</project> </project>