Showing posts with label MAVEN. Show all posts
Showing posts with label MAVEN. Show all posts

Tuesday, August 3, 2021

Maven 3.8.1 Blocks HTTP repositories

The decision was made to block such external HTTP repositories by default

https://stackoverflow.com/questions/66980047/maven-build-failure-dependencyresolutionexception/67018302#67018302


How to fix when I get a HTTP repository blocked?

If the repository is defined in your pom.xml, please fix it in your source code.

If the repository is defined in one of your dependencies POM, you’ll get a message like:

[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project xxx: Failed to collect dependencies at my.test:dependency:version -> my.test.transitive:transitive:version: Failed to read artifact descriptor for my.test.transitive:transitive:jar:version: Could not transfer artifact my.test.transitive:transitive:pom:version from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [blocked-repository-id (http://blocked.repository.org, default, releases+snapshots)]

They go on to offer some ways to avoid the problem:

Options to fix are:

  • upgrade the dependency version to a newer version that replaced the obsolete HTTP repository URL with a HTTPS one,

  • keep the dependency version but define a mirror in your settings.

Plus, I suppose, the simpler, shorter-term option would be to roll back your version of Maven to anything prior to 3.8.1.


Tuesday, April 6, 2021

Maven , mvn , Flags, Multi-Module, repositories, distributionManagement, dependencyManagement, dependencies

https://stackoverflow.com/questions/11778276/what-is-the-difference-between-pom-type-dependency-with-scope-import-and-wit/38470559#38470559

https://stackoverflow.com/questions/25277866/maven-command-line-how-to-point-to-a-specific-settings-xml-for-a-single-command/25279325#25279325

https://blog.sonatype.com/2009/10/maven-tips-and-tricks-advanced-reactor-options/

https://stackoverflow.com/questions/4023597/specify-pom-xml-in-mvn-command-and-mix-goals-of-other-project/4023629#4023629

https://maven.apache.org/pom.html#repositories

https://maven.apache.org/pom.html#distribution-management

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops

https://www.baeldung.com/spring-maven-bom

https://www.baeldung.com/maven-multi-module

  • The dependencyManagement section only declares the dependencies and their details in the current project - the purpose is management of the details and re-use in other projects, either via inheritance (parent) or import (scope). This is like declaring a data type in program and make it available for use.
  • The dependency section defines the actual use of the dependencies in the project, optionally inherit the details (i.e., version, etc.) of the dependencies declared under the dependencyManagment. That's why you will have missing dependencies if you only put them in dependencyManagment. This is analogous to instantiating an variable instance of a data type in a program where it is needed.

  • mvn --settings YourOwnSettings.xml clean installStarting with the Maven 2.1 release, there are new Maven command line options which allow you to manipulate the way that Maven will build multi-module projects. These new options are:-rf, --resume-from Resume reactor from specified project-pl, --projects Build specified reactor projects instead of all projects-am, --also-make If project list is specified, also build projects required by the list-amd, --also-make-dependents If project list is specified, also build projects that depend on projects on the list
  • mvn -f otherPomFile.xml
  •  Whenever a project has a dependency upon an artifact, Maven will first attempt to use a local copy of the specified artifact. If that artifact does not exist in the local repository, it will then attempt to download from a remote repository. The repository/repositories elements within a POM specify those alternate repositories to search. - Basically Download of Binaries from URL.
  • distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed. The repository elements will be used for snapshot distribution if the snapshotRepository is not defined.Basically Upload of Binary to URL.
  • Bill of Materials -Maven - BOM
  •         BOM stands for Bill Of Materials. A BOM is a special kind of POM that is used to control the versions of a project’s dependencies and provide a central place to define and update those versions.
            BOM provides the flexibility to add a dependency to our module without worrying about the version that we should depend on.
# Maven
# Build, test, and deploy with Apache Maven
- task: Maven@3
  inputs:
    #mavenPomFile: 'pom.xml' 
    #goals: 'package' # Optional
    #options: # Optional
    #publishJUnitResults: true 
    #testResultsFiles: '**/surefire-reports/TEST-*.xml' # Required when publishJUnitResults == True
    #testRunTitle: # Optional
    #codeCoverageToolOption: 'None' # Optional. Options: none, cobertura, jaCoCo. Enabling code coverage inserts the `clean` goal into the Maven goals list when Maven runs.
    #codeCoverageClassFilter: # Optional. Comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,-:my.app*.*
    #codeCoverageClassFilesDirectories: # Optional
    #codeCoverageSourceDirectories: # Optional
    #codeCoverageFailIfEmpty: false # Optional
    #javaHomeOption: 'JDKVersion' # Options: jDKVersion, path
    #jdkVersionOption: 'default' # Optional. Options: default, 1.11, 1.10, 1.9, 1.8, 1.7, 1.6
    #jdkDirectory: # Required when javaHomeOption == Path
    #jdkArchitectureOption: 'x64' # Optional. Options: x86, x64
    #mavenVersionOption: 'Default' # Options: default, path
    #mavenDirectory: # Required when mavenVersionOption == Path
    #mavenSetM2Home: false # Required when mavenVersionOption == Path
    #mavenOptions: '-Xmx1024m' # Optional
    #mavenAuthenticateFeed: false 
    #effectivePomSkip: false 
    #sonarQubeRunAnalysis: false 
    #sqMavenPluginVersionChoice: 'latest' # Required when sonarQubeRunAnalysis == True# Options: latest, pom
    #checkStyleRunAnalysis: false # Optional
    #pmdRunAnalysis: false # Optional
    #findBugsRunAnalysis: false # Optional



Monday, April 5, 2021

Dependency Management vs Dependencies POM Maven Difference

What is the difference between dependencyManagement and dependencies?

https://stackoverflow.com/questions/11778276/what-is-the-difference-between-pom-type-dependency-with-scope-import-and-wit/11782691#11782691

Its need to declare dependencies in child project pom's anyway even if they declared in parent project's pom at <dependencyManagement> section

You cannot have a pom type project as a simple dependency in another project. (Well, you can - but it will not do anything useful). There can only be a parent-child relationship. This is essentially managing dependency through inheritance.

import scope for pom type dependency in <dependencyManagement> section allows you to achieve the equivalent of multiple inheritance.


You can only import managed dependencies. This means you can only import other POMs into the dependencyManagement section of your project's POM. i.e.


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>other.pom.group.id</groupId>
            <artifactId>other-pom-artifact-id</artifactId>
            <version>SNAPSHOT</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>   
    </dependencies>
</dependencyManagement>

What then happens is that all the dependencies defined in the dependencyManagement section of the other-pom-artifact-id are included in your POM's dependencyManagement section. You can then reference these dependencies in the dependency section of your POM (and all of its child POMs) without having to include a version etc.

maven command line how to point to a specific settings.xml for a single command?

https://stackoverflow.com/questions/25277866/maven-command-line-how-to-point-to-a-specific-settings-xml-for-a-single-command/25279325#25279325

We usually keep settings.xml in ~/.m2/settings.xml

But its kind of makes it global

What if we want to have our own local settings.xml instead of default and global one,

You can simply use:

mvn --settings YourOwnSettings.xml clean install

or

mvn -s YourOwnSettings.xml clean install


Thursday, March 25, 2021

JavaBrains Microservices POC

[JavaBrains] [Microservices POC]

https://www.youtube.com/watch?v=y8IQb4ofjDo&list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas


#### Spring Boot Microservices Level 1: Communication and Discovery

https://www.youtube.com/watch?v=y8IQb4ofjDo&list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas  


#### Spring Boot Microservices Level 2: Fault Tolerance and Resilience  

https://www.youtube.com/watch?v=o8RO38KbWvA&list=PLqq-6Pq4lTTbXZY_elyGv7IkKrfkSrX5e


#### Spring Boot Microservices Level 3: Microservice configuration  

https://www.youtube.com/watch?v=upoIwn4rWCo&list=PLqq-6Pq4lTTaoaVoQVfRJPqvNTCjcTvJB


Why , We should not hard-code URLS of Services
  • Code Change for URL modification
  • Dynamic Cloud URL
  • Load Balancer URL - Multi Instance URL
  • Multiple Environment Server URLS

When Services Call Each other, How does a Service1 knows about Service2 URL ?

  • Service Discovery - Design Pattern 
  • Eureka - Technology used for implementing "Service Discovery"


Client Side Service Discovery vs Server Side

Client Side Service Discovery
Client  -> Service Discovery Server
               Looks Up IP address of Service1
           <- Provides IP Address to Client
Client -> Call to Service 1
Client <- Gets a response from Server1

Server-Side Service Discovery
Client Calls Service Discovery asks it to Send "Hi" on its behalf to Service1
Service1 Sends "Hello" response to Discovery Server and its forwarded to Client


Other Technologies which have come from Netflix OSS or developed by Spring Boot
  • Hysterix - Fault Tolerance Library
  • Zuul - Gateway
  • Ribbon
  • Feign


POM Management

spring-cloud-starter-netflix-eureka-server
spring-cloud-starter-netflix-eureka-server

<properties>
	<java.version>11</java.version>
	<spring-cloud.version>2020.0.2</spring-cloud.version>
</properties>
<dependencies>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>${spring-cloud.version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

  • @LoadBalanced
  • @EnableEurekaClient
  • @EnableEurekaServer


EurekaClient sends heartbeat to EurekaServer
So, If A Service Goes Down, After Maybe about 30 Seconds,
The Entry gets removed from Dashboard of Eureka Server


#### Spring Boot Microservices Level 1: Communication and Discovery
https://www.youtube.com/watch?v=y8IQb4ofjDo&list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas  

#### Spring Boot Microservices Level 2: Fault Tolerance and Resilience  
https://www.youtube.com/watch?v=o8RO38KbWvA&list=PLqq-6Pq4lTTbXZY_elyGv7IkKrfkSrX5e

#### Spring Boot Microservices Level 3: Microservice configuration  
https://www.youtube.com/watch?v=upoIwn4rWCo&list=PLqq-6Pq4lTTaoaVoQVfRJPqvNTCjcTvJB

Adding Spring Cloud To An Existing Spring Boot Application

If you an existing Spring Boot app you want to add Spring Cloud to that app, the first step is to determine the version of Spring Cloud you should use. The version you use in your app will depend on the version of Spring Boot you are using.

The table below outlines which version of Spring Cloud maps to which version of Spring Boot.

Table 1. Release train Spring Boot compatibility
Release TrainBoot Version

2020.0.x aka Ilford

2.4.x

Hoxton

2.2.x, 2.3.x (Starting with SR5)

Greenwich

2.1.x

Finchley

2.0.x

Edgware

1.5.x

Dalston

1.5.x


Saturday, January 30, 2021

Maven to Spring Application.Properties - Profile

 #server.port=8081

spring.profiles.active=@activatedProperties@

https://www.petrikainulainen.net/programming/tips-and-tricks/creating-profile-specific-configuration-files-with-maven/


<profiles>

<!-- DEV Build -->

<profile>

<id>DEV1</id>

<properties>

<activatedProperties>DEV1</activatedProperties>

</properties>

</profile>


<!-- AZURE Build -->

<profile>

<id>QA</id>

<properties>

<activatedProperties>QA</activatedProperties>

</properties>

</profile>

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass