I want to use docker-maven-plugin to deploy PostgreSQL container and run some integration tests over it.
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.0</version>
<executions>
<execution>
<id>prepare-it-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<images>
<image>
<name>postgres:9.5.4</name>
<alias>it-database</alias>
<run>
<ports>
<port>it-database.port:5432</port>
</ports>
<wait>
<log>database system is ready to accept connections</log>
<time>20000</time>
</wait>
</run>
</image>
</images>
</configuration>
</execution>
</executions>
</plugin>
Is it possible to run another goal (mvn e.g. flyway:migrate) from this plugin?
No, this plugin does not execute other Maven plugins (and very few do that).
What you need to do is to bind d-m-p's start goal to pre-integration-test, and then also bind flyway plugin to pre-integration-test Maven phase.
Related
I'm setting up an integration testing environment for my Spring Boot Java application. So I'm spinning off a PostgreSQL database using docker-maven-plugin, which my application is supposed to call into.
This setup works ok when running mvn verify on my local system, but on the GitLab CI runner, is failing, because the PostgreSQL hostname doesn't match anymore.
My question is, how can I get the hostname of the database container in the CI pipeline?
My plugin configuration looks something like this:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.maven.plugin.version}</version>
<executions>
<execution>
<id>prepare-it-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<images>
<image>
<name>postgres:9.6.14</name>
<alias>it-database</alias>
<run>
<ports>
<port>it-database.port:5432</port>
</ports>
<wait>
<log>(?s)database system is ready to accept connections.*database system is ready to accept connections</log>
<time>20000</time>
</wait>
<log>
<prefix>POSTGRESQL-TEST</prefix>
<date>ISO8601</date>
<color>blue</color>
</log>
</run>
</image>
</images>
</configuration>
</execution>
<execution>
<id>remove-it-database</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Eventually, I will have to pass that database hostname in my application yaml:
spring:
datasource:
platform: postgresql
url: jdbc:postgresql://<db_host_name_here_once_i_get_it>:${it-database.port}/postgres
username: postgres
password: postgres
schema: classpath:schema-postgresql.sql
data: classpath:data-postgresql.sql
driver-class-name: org.postgresql.Driver
initialization-mode: always
I have a maven project which creates a war file and this should be deployed to a bundled wildfly server via wildfly:run.
That works so far, but I need to create a datasource before deploying.
I have tried to bind the add-resource goal to different phases like deploy, install or package. None of them worked.
What is wrong?
An idea would be to use the wildfly:start attach an execution to add the datasource and deploy the application, but I don't know how.
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>add-datasource</id>
<phase>deploy</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources,data-source=java:jboss/testDB</address>
<resources>
<resource>
<properties>
<jndi-name>java:jboss/testDB</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver-class>org.h2.Driver</driver-class>
<driver-name>h2</driver-name>
<user-name>sa</user-name>
<password>sa</password>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
My solution is to use the run goal and the beforeDeployment goal:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<beforeDeployment>
<commands>
<command>data-source add --jndi-name=java:jboss/datasources/OracleDS --name=testDB --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 --driver-name=h2 --user-name=sa --password=sa</command>
</commands>
</beforeDeployment>
</configuration>
</plugin>
I have a project for which I have created a pom.xml. However, I'm not using Maven as my build system, I am using something else (e.g. ANT). But I want the pom.xml to exist for the use of other tools, e.g. IDEs. How can I make sure, that if someone downloads my project and tries to build it with Maven, they will get a clear indication that they are doing the wrong thing?
Add the following to pom.xml:
<properties>
<maven.build.not.supported>
Do not use Maven to build this module. Please see README.html for
instructions on how to build it.
</maven.build.not.supported>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>fail-clean-lifecycle</id>
<phase>pre-clean</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>fail-default-lifecycle</id>
<phase>validate</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>fail-site-lifecycle</id>
<phase>pre-site</phase>
<configuration>
<tasks>
<fail message="${maven.build.not.supported}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Since we cannot apparently bind a plugin execution to multiple phases, we need to repeat the execution block three times, one for each of the built-in lifecycles (clean, default and site). To avoid duplication of the failure message, we store it in a Maven property and reuse that property in each execution. In each execution we bind to the first phase of the lifecycle to fail it immediately.
how do I specify build goals like development, test or production environment in the maven grails plugin when packaging a war file for deployment?
Thanks
Set grails.env when running maven:
mvn package -Dgrails.env=development
If you omit this option, the environment defaults to production.
You can also set it in the <configuration> section
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.3.7</version>
<executions>
<execution>
<goals>
<goal>maven-war</goal>
</goals>
<configuration>
<env>prod</env>
</configuration>
</execution>
</executions>
</plugin>
I'm trying to install a wsdl file into a remote Maven repository so I can reference it in a CXF project as per this blog post.
I'm sure it could be done manually, but I want an actual maven project so I can make use of the release plugin for tagging etc.
Has anybody got experience with this?
You can use the build helper maven plugin to do this. Here is an indicative code snippet
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${wsdlLocation}/project.wsdl</file>
<type>wsdl</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build.