Building docker image locally with Jib - docker

I am trying to build docker image locally with Jib for project but am stuck at this issue. Can some one help me to find the solution?
This is the plugin i used in pom.xml
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<from>
<image>openjdk:16</image>
</from>
<container>
<ports>
<port>8080</port>
</ports>
<format>OCI</format>
</container>
</configuration>
</plugin>

jib-maven-plugin calls methods of com.google.common.base.Preconditions provided by Guava. It seems that for some reason, the runtime classpath for jib-maven-plugin has an old version of Guava. (This can happen, for example, if you have another plugin that pulls in an old version.)
You can force a specific version for a plugin runtime classpath. Here's an example:
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.1.4</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
</dependencies>
<configuration>
(BTW, I'm using the latest Jib 3.1.4 and the corresponding Guava version.)

Related

Multi-module maven microservices deploy to Heroku

I have a microservices project with a parent POM and all the other modules with an internal POM.
Locally, if I run mvn clean install -DskipTests everything works.
I want to deploy all the microservices to Heroku, how can i do this?
The project works also for Docker & Kubernetes, is there a way to integrate also Docker in Heroku?
So it will be beautiful if I can deploy all the microservices as 1 project in Heroku, with every microservices as a Docker image.
Thank you in advance!
This is an example of my project:
Parent POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.petcare</groupId>
<artifactId>website-petcare-backend</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-pom</name>
<modules>
<module>apiGateway</module>
<module>reservationService</module>
<module>userService</module>
<module>eurekaServer</module>
<module>mapService</module>
<module>authService</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Build
You can build all images for the sub-modules using the docker-maven-plugin.
Each sub-module must have its own Dockerfile, then in the parent POM add:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.38.1</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
When running mvn clean package docker:build all projects are built and Dockerized
Deploy
Deploying all images (each image into its own web Dyno) is a little bit more complicated. You have few options:
Script from the command line: typically you can push the image with the following commands
heroku container:push web -a appname
heroku container:release web a appname
You could build a script that performs those steps for each and (very important) performs both the heroku login and heroku:container login using the credentials
Using heroku.yml where you can define at once all the containers to be deployed. It is a good approach but you need to git push your changes (see here)
Use CI/CD application like Github Actions. In this case your workflow compiles, tests, builds and pushes the application.
This is my preferred approach: you can decide when to build/deploy (on master push? manually?), you save the Heroku credentials as secrets, you can automate the release pipeline.
You can read more here
You can also try the Heroku Docker Maven plugin if you like to control all services using Maven

Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:2.4

Thanks to a Dropwizard Maven archetype I generated a sample Dropwizard Maven project. The pom.xml notably uses maven-source-plugin:
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
When I run "clean install" I have the following error :
Plugin org.apache.maven.plugins:maven-source-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:2.4: Could not transfer artifact org.apache.maven.plugins:maven-source-plugin:pom:2.4 from/to central (http://repo.maven.apache.org/maven2): Connection refused: connect -> [Help 1]
The "maven-source-plugin" dependency is stored in the Nexus repository of my company. So I tried the adding of the plugin dependency between dependencies and /dependencies :
<dependencies>
...
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
but it did not correct the problem. I also tried to add the dependency at the call of the plugin :
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</plugin>
but it did not work either
Two possible situations :
Your company uses a proxy to connect to the public Maven repository. Then ask someone in your company what the IP address of the proxy is then put it in your settings.xml file
Your company has its/their own Maven repository/ies (Nexus repository for example). Then ask someone in your company what the Nexus repository is then put it in your pom.xml or in your settings.xml. See Adding maven nexus repo to my pom.xml and https://maven.apache.org/guides/mini/guide-multiple-repositories.html
It may happen, e.g. after an interrupted download, that Maven cached a broken version of the referenced package in your local repository.
Solution: Manually delete the folder of this plugin from cache (i.e. your local repository), and repeat maven install.
How to find the right folder? Folders in Maven repository follow the structure:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
</dependency>
is cached in ${USER_HOME}\.m2\repository\org\apache\maven\plugins\maven-source-plugin\2.4
Update the apache-maven-3.5.0-bin\apache-maven-3.5.0\conf\settings.xml file.
Check your internet explorer proxy --> Setting --> Internet explorer -->Connection --> LAN Setting
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>user</username>
<password>****</password>
<host>proxy</host>
<port>8080</port>
</proxy>
I am using JDK 7 for maven project and I used -Dhttps.protocols=TLSv1.2 as argument in JRE. It has allowed to download all maven repository which were failing earlier.
org.apache.maven.plugins:maven-source-plugin does not exist in the repository http://repo.maven.apache.org/maven2.
You have to download it from Maven central where it exists => maven-source-plugin
Verify your pom definition or your settings.xml file.
so I am assuming that this project you are doing in your private eclipse (not company provided eclipse where you work). The same problem I resolved just as below
quick fix : got to .m2 file --> create a backup of settings.xml --> remove settings.xml --> restart your eclipse.
On my side it was coming from an error in my settings.xml file.
I had a bad tag. Just removed it, refreshed and i was good to go.
Remove the content of the folder \.m2\repository\org\apache\maven\plugins\maven-resource-plugin\2.7. The cached info turned out to be the issue.
I use intelliJ and finally I created my own settings.xml and added the following content structure to it. In my project's pom.xml, the nexus repositories were defined but for some reason it was always hitting the external apache maven repo which is blocked in my company.
<settings>
<mirrors>
<id>nexus</id>
<url>nexusURL </url>
<mirrorOf>central</mirrorOf>
<mirror>
<profiles>
<profile>
<repositories>
<repository>
</settings>

maven dependency:copy across modules

Have a project with several module projects and itself having other module projects. I have certain modules generating a special artifact type '.kar', and I am deploying this to artifactory during maven deploy phase.
Now I want to find a way by using this existing pom to download these specific artifacts from artifactory by version.
mvn dependency:copy <> allows me to download this per specific artifact.
I want this to be done via the pom file which generates these artifacts. Problem is when I use the dependency:copy, it only runs on the current pom which may or may not have the special artifact.
If I use it in then it re-deploys all the artifacts and downloads the special artifact correctly. This is not right solution though.
You could add a new module to your project that has <dependencies> to all of your .kar artifacts. In the POM file of this new module you can use the copy-dependencies goal of the maven-dependency-plugin.
<project>
<!-- Integrate this module into your multi-module project. -->
<parent>
<groupId>my.group.id</groupId>
<artifactId>my-parent-pom</artifactId>
<version>1.0.0-SNAPSHOT</version<
</parent>
...
<!-- Add dependencies for all your .kar artifacts. -->
<dependencies>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>kar-artifact-1</artifactId>
<version>${project.version}</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>my.group.id</groupId>
<artifactId>kar-artifact-2</artifactId>
<version>${project.version}</version>
<type>kar</type>
</dependency>
...
</dependencies>
<build>
<plugins>
<!-- Use the maven-dependency-plugin to copy your .kar artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-kar-artifacts</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeTypes>kar</includeTypes>
</configuration>
</execution>
</executions>
<plugin>
</plugins>
</build>
</project>

unable to convert my maven to eclipse

Please, I am new to maven and trying to build my first maven project. So, here are a few things I did:
from my command line into a directory called MavenProject I created:
mvn archetype:generate
and then choose a number to apply number, I entered 15 then;
Choose com.dyuproject.protostuff.archetype:basic-webapp version:
I chose version 1.0.7
groupId: com.henry
artifactId: HibernateTest
and the rest, I just entered..
and the project was created but then I typed in mvn eclipse:eclipse, I got an error that there was no pom.xml file even though I can see there is one in my mavenProject. so, I changed into the HibernateTest directory and in that directory, I tried the mvn eclipse:eclipse command again but this time, it gave the eorror:
Plugin com.dyuproject.protostuff:protostuff-maven-plugin:1.0.2-SNAPSHOT or one of its
dependencies could not be resolved: Failed to read artifact descriptor for
com.dyuproject.protostuff:protostuff-maven-plugin:jar:1.0.2-SNAPSHOT: Could not find artifact
com.dyuproject.protostuff:protostuff-maven-plugin:pom:1.0.2-SNAPSHOT
I tried to solve this by going to mvnrepository.com and found the protostuff maven and added the dependencies but still couldn't solve it. here is my pom.xml file:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLS$
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_$
<parent>
<artifactId>Hibernate</artifactId>
<groupId>com.henry</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.henry</groupId>
<artifactId>Hibernate-model</artifactId>
<name>Hibernate :: model</name>
<packaging>jar</packaging>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>${protostuff.version}</version>
<configuration>
<protoModules>
<protoModule>
<source>src/main/resources/com/henry/model/model.proto</source>
<outputDir>src/main/java</outputDir>
<output>java_bean</output>
<encoding>UTF-8</encoding>
<options>
<property>
<name>generate_field_map</name>
</property>
<property>
<name>separate_schema</name>
</property>
<property>
<name>builder_pattern</name>
</property>
<property>
<name>generate_helper_methods</name>
</property>
</options>
</protoModule>
</protoModules>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-codegen</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-maven-plugin</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-codegen</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-compiler</artifactId>
<version>1.0.7</version>
</dependency>
</dependencies>
</project>
Any help will be appreciated. Sorry am a newbie :)
First try to build the project on the command line: mvn install. That should succeed.
But it looks like it won't, as it is looking for a SNAPSHOT dependency version of ${protostuff.version}. When I look in the Maven central repository, there's really only release versions (as it should be). Somehow you have to fix that, probably in your parent project.
The POM file should be in the root of the project and called pom.xml. Where you find the POM file called pom.xml is the root of the project :)
Only use eclipse:eclipse as a last resort. If you have free choice of Eclipse, and you have no wizardry in your Maven projects, you should be able to use the m2e (m2eclipse) Eclipse plugin.
That's an Eclipse plugin, not a Maven plugin, so no additional steps are needed on the command line. Just go into Eclipse, make sure the m2e plugin is installed. Then import your project (Import, "Existing Maven Projects").
All the files that Eclipse needs for its own bookkeeping should be created upon import and be based on the POM file. I.e. .classpath, .project and .settings (folder). If you have any of those prior to importing into Eclipse, you may be better off removing them (they may be remnants of your eclipse:eclipse attempts.

How to wrap an Ant v.1.8.1 build with Maven v. 2.x?

I need to build project with subprojects and main project is the Maven project, one of the subprojects - is the Ant project.
I need to compile all projects from one main pom.xml
I have found solution How to wrap an Ant build with Maven? and it's answer is correct, but not for my project. Because when my ant project required Ant v. 1.8.x, but on build with the
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<modules>
<module>Bundles/I_AboutForm</module>
<module>Bundles/I_AppVars</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<!--<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath" />-->
<tasks>
<ant antfile="MainApplication/build.xml" target="compile"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
maven downloaded Ant v. 1.7.1 and uses him on build (in the local repo has Ant v.1.8.1).
I think, may be trouble in the dependings of the ant-contrib 1.0b3 - may be ant-contrib depends on Ant v. 1.7.1?
Please advice me how to build Ant v. 1.8.x project in Maven.
Thanks, best regards, Arthur.
looking at the version of the plugin 1.7, it seems to use the ant version 1.8.2
http://maven.apache.org/plugins/maven-antrun-plugin/dependencies.html
Try to specify the version 1.7 of the plugin maven-antrun-plugin
for example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>

Resources