Save 37% off PRO during our Black Friday Sale! »

Maven-Geheimnisse unlocked – verbessern Sie Ihren Build

C59c6666e76977dde33948515fdb3a90?s=47 ElmarDott
December 08, 2020

Maven-Geheimnisse unlocked – verbessern Sie Ihren Build

Apache Maven ist seit mehr als einem Jahrzehnt als Build- und Reporting-Tool für Java-Projekte etabliert. Der Erfolg dieses Tools wurde, weil es als eines der ersten Build-Tools eine einfache Lösung für das Abhängigkeitsmanagement ansprach. Entwickler lassen mehrmals am Tag einen Maven-Build laufen, wissen aber oft nicht, wie sie Probleme beheben können, wenn ein Build kaputt ist.

In diesem praxisorientierten Vortrag beginnen wir mit den Grundlagen und gehen schnell zu fortgeschrittenen Themen über und lernen, wie man den Lebenszyklus eines Builds modifiziert:

-Token-Ersatz für die Datenbankkonfiguration
-Ausführbare jar-Dateien
-Paket-Fat-Jar einschließlich Abhängigkeiten & MANIFEST-Manipulation
-Arbeiten mit Webanwendungen & Multi-Modul-Projekten
-Erzwingen von Java-Kompilierungsversionen & Release-Zusammenhängen
-Konfigurieren der Reporting-Engine

Homepage : https://enrebaja.wordpress.com
AnchorFM : https://anchor.fm/elmar-dott
Twitter - https://twitter.com/ElmarDott
GitHub - https://github.com/ElmarDott
Lbry - https://lbry.tv/@elmar.dott:8
BitChute - https://www.bitchute.com/channel/3IyCzKdX8IpO/
--------------------------------------------------------------------------------------------------
YouTube Conference List - https://www.youtube.com/watch?v=VOwVfG0tbpM&list=PL2ZvHPhC-ji_1VIe6SY_j6By1uhkF4CWD

C59c6666e76977dde33948515fdb3a90?s=128

ElmarDott

December 08, 2020
Tweet

Transcript

  1. Maven secrets unlocked - enhance your build (c) 2020 M.

    Schulz
  2. speaker + Project Manager + Consultant + Writer + Speaker

    + Trainer + CC BY-ND Marco Schulz ElmarDott studied at HS Merseburg, Germany, computer science and holds an engineers degree in software engineering. The main topics in his field of work are Software Architectures, automatism of the software development process and Software Configuration Management. Since more than 15 years he work in different large Web Application Projects. Currently he work as independent Consultant, Trainer and publish plenty articles in several computer magazines. Mail: marco.schulz@outlook.com IT-Tage FFM 2020 M. Schulz
  3. agenda CC BY-ND • maven basics • build life cycle

    • project object model • project structure • dependency management • properties • samples IT-Tage FFM 2020 M. Schulz
  4. terms CC BY-ND Artefact: is a independent pice of software

    like a library, module or plugin. Life-Cycle: Maven has three different Lifecycles for software development: Build, Clean and Site. Phase: divides the Build-Lifecycle into 23 parts. The Lifecycle walk through the phases in a defined ordering. Goal: are defined by a Maven-Plugin (MOJO) and describe a sub task inside the plugin. Dependencies are Artefactes which stored in a local or remote Repository for reuse in other projects. IT-Tage FFM 2020 M. Schulz
  5. build life cycle CC BY-ND Phase Description 15 - test

    run tests in a configured test framework 17 - package package the compiled code in a distributive format 21 – verify execute integration test 22 – install copy the artifact to a local repository 23 – deploy upload the artifact to a remote repository Command Line: $~ mvn <phase>:<plugin>:<goal> IT-Tage FFM 2020 M. Schulz
  6. mvn command line CC BY-ND IT-Tage FFM 2020 M. Schulz

    % default phases in debug mode $~ mvn {clean | site | package | verify | install | deploy} -X % the preferred way $~ mvn clean install → $~ mvn verify % call profiles $~ mvn package -P release javadoc % call a specific plugin goal $~ mvn versions:display-plugin-updates % overwrite properties $~ mvn package -DskipTests=true % alternative settings.xml $~ mvn package -S settings.xml
  7. standard project layout CC BY-ND /subfolder : module pom.xml :

    module-pom /src /main /filter : token replacement /java : source /resources : non-source /webapp : web.xml etc. /test /java : test sources /resources : test non source /site : reporting /resources /site.xml : site descriptor /target : build output /pom.xml project view in NetBeans IT-Tage FFM 2020 M. Schulz
  8. types of a POM CC BY-ND SUPER POM REACTOR POM

    PROJECT POM PARENT POM MODULE POM POM WAR EAR ABSTRACT POM JAR / WAR / EAR POM IT-Tage FFM 2020 M. Schulz
  9. sample POM CC BY-ND 01: <?xml version="1.0" encoding="UTF-8"?> 02: <project>

    03: <modelVersion>4.0.0</modelVersion> 04: <parent> 05: <groupId>org.sample</groupId> 06: <artifactId>parent-pom</artifactId> 07: <version>1.0</version> 08: </parent> 09: <groupId>org.sample</groupId> 10: <artifactId>project-name</artifactId> 11: <version>1.0-SNAPSHOT</version> 12: <packaging>pom | jar | war | ear | zip</packaging> 13: <modules> 14: <module>subfolder</module> 15: </modules> 16: </project> IT-Tage FFM 2020 M. Schulz
  10. dependency management CC BY-ND 01: <?xml version="1.0" encoding="UTF-8"?> 02: <project>

    03: <modelVersion>4.0.0</modelVersion> 04: <groupId>org.sample</groupId> 05: <artifactId>project-name</artifactId> 06: <version>1.0-SNAPSHOT</version> 07: <packaging>jar</packaging> 08: <depenedencies> 09: <depenedency> 10: <groupId>junit</groupId> 11: <artifactId>junit</artifactId> 12: <version>4.13</version> 13: <scope>test</scope> 14: </depenedency> 15: </depenedencies> 16: </project> IT-Tage FFM 2020 M. Schulz
  11. maven scopes CC BY-ND compile - (default) Compile dependencies are

    available in all classpaths of a project. provided - Indicates you expect the JDK or a container to provide the dependency at runtime. This scope is only available on the compilation and test classpath, and is not transitive. runtime - The dependency is not required for compilation. It is in the runtime and test classpaths, but not the compile classpath. test - The dependency is only available for the test compilation and execution phases. This scope is not transitive. system - This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. import - Only supported on a dependency of type pom in the <dependencyManagement> section. It indicates the dependency to be replaced with the effective list of dependencies in the specified POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency. IT-Tage FFM 2020 M. Schulz
  12. variables aka properties CC BY-ND 01: <?xml version="1.0" encoding="UTF-8"?> 02:

    <project> 03: <modelVersion>4.0.0</modelVersion> 04: <groupId>org.sample</groupId> 05: <artifactId>project-name</artifactId> 06: <version>1.0-SNAPSHOT</version> 07: <packaging>jar</packaging> 08: <propertries> 09: <spring.version>5.3.0</spring.version> 10: <properties> 11: <depenedencies> 12: <depenedency> 13: <groupId>org.springframework</groupId> 14: <artifactId>spring-framework-bom</artifactId> 15: <version>${spring.version}</version> 16: <type>pom</type> 17: <scope>import</scope> 18: </depenedency> 19: </depenedencies> 20: </project> IT-Tage FFM 2020 M. Schulz
  13. samples CC BY-ND practical demonstration on Ubuntu MATE & NetBeans

    IDE 01 > token replacement :: database configuration 02 > compiler warnings :: quality 03 > executable jar files 04 > enforcement :: release builds 05 > Unit & Integration testing 06 > working with web apps & multi module projects 07 > BOM – Bill of Materials :: dependency management „ A Fool with a Tool is still a fool.“ Grady Booch IT-Tage FFM 2020 M. Schulz https://github.com/ElmarDott/SamplesAndTrainings/tree/master/mvn-samples
  14. Thank you / Danke / Gracias CC BY-ND IT-Tage FFM

    2020 M. Schulz