Apache Maven

Apache Maven

Java Distribution

Distribution Intermezzo

What does it take to build,
distribute & run java application?

What are the distribution options?

Java Distribution

What is Maven

  • From Yiddish word meaning "Expert"
  • Originally developed to simplify build of Jakarta Turbine
  • A tool used to build and manage Java-based projects
  • Currently in version 3.9.x
  • Apache Maven
Java Distribution

Maven's Goals

  1. Making the build process eas(y/ier)
  2. Providing a uniform build system
  3. Providing quality project information
  4. Encouraging better development practices
Java Distribution

Maven What?

  1. Describes how to build your project via POM file descriptor
  2. Allows you to define useful metadata about your project
  3. Provides dependency management
  4. There are reasonable defaults
Java Distribution

Project structure

project_root
|- src
    |- main
        |- java
        |- resources
    |- test
        |- java
        |- resources
|- pom.xml
Java Distribution

Project Object Model

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>cz.muni.fi.pv168</groupId>
    <artifactId>zinger</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>
Java Distribution

Maven Dependencies

  • Maven projects can be published to repositories
  • Default remote repository is Maven Central
  • Ability to use multiple repositories
  • Local repository in ${M2_HOME}/repository typically ~/.m2/repository on Unix systems
Java Distribution

POM Example

Let's look at full pom.xml

  • What dependencies does this project have?
  • What is the build output?
  • What metadata does the project provide?
Java Distribution

Maven Alternatives

"I don't like it, what are the other options?"

  • Though luck, you need it!
  • There is one, Gradle
  • You still need to know Maven!
Java Distribution

PV168

The Calculator Application

Java Distribution

Back to the original version

  • Where the code does come from?
    • It is an example from GeeksForGeeks website on how to use Java Swing
  • What was wrong with it?
  • How would you call these problems in the code?
    • The industry standard term is Code Smell
Java Distribution

Now to the reworked version

  • What was better in this reworked version?
  • How did it happen that we have it?
  • How would you call these transformations of the code?
    • The industry standard term is Refactoring
Java Distribution

Code Smells vs. Refactoring

  • A little bit of medical analogies
    • Code Smell tells us what the code suffers from (diagnosis)
    • Refactoring describes how we can cure it (therapy)
  • Where do these terms come from?
Java Distribution

Recommended reading

Refactoring: Improving the Design of Existing Code, 2nd edition

Martin Fowler, Kent Beck

Addison-Wesley Professional, 2019

https://www.amazon.com/gp/product/B07LCM8RG2

Java Distribution

Code Smells in the original version

  • Mysterious Name
  • Long Function
  • Duplicated Code
  • Comments

Java Distribution

The Most Usefull Refactorings

  • Rename
  • Extract Method
  • Extract Variable
  • Inline

Java Distribution

What is Refactoring

  • Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.

    (Martin Fowler, Refactoring, page 45)

  • Refactoring (verb): to restructure software by applying a series of refactorings without changing its observable behavior.

    (Martin Fowler, Refactoring, page 45)

Java Distribution

What is not Refactoring

  • If someone says their code was broken for a couple of days while they are refactoring, you can be pretty sure they were not refactoring.

    (Martin Fowler, Refactoring, page 45)

Java Distribution

Key Requirement

  • Before you start refactoring, make sure you have a solid suite of tests.

    (Martin Fowler, Refactoring, page 5)

Java Distribution

Test Categories

  • End-to-End
    • Testing the whole system, starting at the GUI down to the persistence
    • Automating them is out of scope of PV168
  • Integration
    • Testing collaboration of multiple components
  • Unit
    • Testing a single unit (in isolation)
Java Distribution

Usability Problems in the Calculator

  • There were many of them
  • But the most prominent was ...
    • The layout