Maven - Java

  • Maven will build, document, and report source code of the project
  • Maven is similar to NPM
    • JDBC is similar to Node JS
    • ECMA made JS standard similar to Java made JDBC & JPA
    • Spring Boot is similar to React framework
  • 7 DevOps Lifecycle Phases
  • MAVEN Commands
    • mvn -v => Check version
    • Create MAVEN Project
      • mvn archetype:generate -DgroupId=com.accenture.lkm -DartifactId=dependency-counter-maven-plugin -Dversion=0.0.1-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo
    • mvn compile => Compile maven project
    • mvn test-compile => Compile test files
    • mvn test
    • mvn package => Generate jar file
    • Testing the Plugin
      • mvn clean install
    • Generate Test Report
      • mvn surefire-report:report
    • Executing Plugin
      • mvn com.accenture.lkm:dependency-counter-maven-plugin:0.0.1-SNAPSHOT:dependency-counter
    • Executing Plugin with Scope property
      • mvn com.accenture.lkm:dependency-counter-maven-plugin:0.0.1-SNAPSHOT:dependency-counter -Dscope=provided
    • mvn clean install -U
  • Config MAVEN on local system – m2_home env_variable
  • How to create MAVEN project – CMD & Eclipse
  • Project Structure
  • MAVEN Dependencies (form.xml)
    • Direct & X
    • Scope – Test, Provided, Runtime …
    • Build Lifecycle – Default, Site …
    • CMD – MAVEN test, …
  • Packing
  • Clean previous project
  • MAVEN Plugins => Build, Reporting
    • Add reporting plugin
          <reporting>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.0.0-M7</version>
              </plugin>
            </plugins>
          </reporting>
      
    • MAVEN Custom Plugin
      • Archetypes – maven-archtype-mojo or maven-archtype-plugin
      • Run
        • cd maven_ex
        • mvn archetype:generate -DgroupId=com.accenture.lkm -DartifactId=dependency-counter-maven-plugin -Dversion=0.0.1-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo
  • MOJO (Maven plain Old Java Object)
  • MAVEN Repositories – mroot
    • Central – repo.org
    • Remote / Private repo – form.xml config
  • Code Quality Review
    • Good Application Characteristics
  • Static Code Analysis
    • It is for examining the source code wheather it adheres to industry standards
    • Done without code execution
    • Tools
      • CheckStyle
      • PMD
      • Find Bugs
  • Sonarqube
    • Quality management platform, that does constant source code technical quality check
    • Sonarqube Installation & Configuration
      • Download community edition zip file from their website
      • Extract Sonarcube, Sonarscanner, JDK 17 in C drive
      • Set env variable
      • Run Sonarcube (from extracter sonarcube folder from CMD)
      • URL http://localhost:9000/
      • admin is Login & Password => Change password
      • Add in form.xml
            <build>
            <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.4</version>
            </plugin>
            <!-- other plugins -->
            </plugins>
        
            <pluginManagement>
            <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
            <lifecycleMappingMetadata>
            <pluginExecutions>
            <pluginExecution>
            <pluginExecutionFilter>
            <groupId>
                   org.apache.maven.plugins
            </groupId>
            <artifactId>
                   maven-plugin-plugin
            </artifactId>
            <versionRange>[3.4,)</versionRange>
            <goals>
            <goal>descriptor</goal>
            </goals>
            </pluginExecutionFilter>
            <action>
            <execute/>
            </action>
            </pluginExecution>
            </pluginExecutions>
            </lifecycleMappingMetadata>
            </configuration>
            </plugin>
            </plugins>
            </pluginManagement>
            </build>
        
      • Others
            sonar-project.properties
            sonar.projectName=plugin_demo
            sonar.projectKey=pluginKey
            sonar.sources=src/main/java
            sonar.host.url=http://localhost:9000/
            sonar.token=sqp_d0e5bcc52c3f981bf3e8974dbefe93fb4627eacf
        
      • Help > Eclipse MarketPlace
  • Quality Gates
  • Architecture
  • Scan a Maven project - Static Code Analysis
  • Sonarlint plugin
Share: