I'm trying to convert this plugin in pom to gradle. And I've added
compile 'org.codehaus.mojo:exec-maven-plugin:1.2.1' in the dependencies. There are some other parameters like "includeProjectDependencies" and so on. Just don't know what else to put in "JavaExec":
task executeJava(type:JavaExec) {
main = "com.abc.efg.func.DocumentGenerator"
classpath = sourceSets.main.runtimeClasspath
dependsOn = files('/lib/tool.jar')
args = [
"--api_list",
"metaapi#v1",
"campaign#v1",
"--output_directory",
"$project.buildDir"
]
}
Here's the plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>com.abc.efg.func.DocumentGenerator</mainClass>
<executableDependency>
<groupId>com.google.template</groupId>
<artifactId>tool</artifactId>
</executableDependency>
<arguments>
<argument>--api_list</argument>
<argument>metaapi#v1,campaign#v1</argument>
<argument>--output_directory</argument>
<argument>${project.build.directory}</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.template</groupId>
<artifactId>tool</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
Related
I googled a lot but I didn't find a proper solution to my question. So maybe here.
There is a Spring Boot service that I would like to test through REST API in build time. So the service needs to be executed as a standalone service in the build phase before the integration tests are executed.
I can execute somehow it but not the ideal.
I did something similar that the this article
I have a maven project with this 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>my.project.package</groupId>
<artifactId>my-project-name</artifactId>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>my-project-name</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<parallel.tests>3</parallel.tests>
<serenity.maven.version>2.0.48</serenity.maven.version>
<cucumber.version>4.8.0</cucumber.version>
<serenity.version>2.1.2</serenity.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16-beta1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber4</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-spring</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>**/*Runner.java</include>
</includes>
<parallel>classes</parallel>
<threadCount>${parallel.tests}</threadCount>
<forkCount>${parallel.tests}</forkCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I made an entry point for the test execution:
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
features = "src/it/resources/features",
glue = "my.project.package.integrationtest",
plugin = {
"pretty"
},
tags = "(not #Ignore) or (not #Manual) or (not #ToBeImplemented)"
)
#ActiveProfiles("integration-test")
public class IntegrationTestRunner {}
I have a StepsBase class which starts the app:
#RunWith(SpringRunner.class)
#SpringBootTest(webEnvironment = RANDOM_PORT)
#ActiveProfiles("integration-test")
#ContextConfiguration(classes = Application.class)
public class StepsBase {
public static final String HOST = "http://localhost:";
#LocalServerPort
private int serverPort;
public String getBaseUrl() {
return HOST + serverPort;
}
}
And all my steps classes extends the StepsBase class like this
public class SimpleSteps extends StepsBase {
#Given("this is a sample step")
.
.
.
}
If I execute the service build with maven clean verify, then I get the following log for the integration tests:
The main problem with this solution is the first scenario execute the Spring Boot service before instantiating the step class, which is counting into the execution time, and the test cases are not compromised if the service is not starting. Bytheway the Serenity before every scenario checks that the service is running or not.
Do you have an idea of how to make that the service is started before Serenity startup?
Or before the first step execution?
If everything is in the same project (or maven module) you can use the Spring Boot Maven plugin (https://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html). A sample configuration is shown below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.4.RELEASE</version>
<configuration>
<classifier>exec</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
```
This is a new project, created clicking New project -> Java with Maven -> JavaFX Application
As the project is crated, all lines of code related to javafx gerate an error "package javafx.application does not exist".
During the creation of the project I have been asked to unstall the javafx plugin, so I did.
Here is my MainApp.class
package com.mycompany.mavenproject1;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainApp extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add("/styles/Styles.css");
stage.setTitle("JavaFX and Maven");
stage.setScene(scene);
stage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Here is the pom file:
<?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.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mavenproject1</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.mycompany.mavenproject1.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
</project>
How would I access the actual fully qualified path so that I can write a file to it in the groovy script?
the properties
<properties>
<gen.resources.config>target/generated-resources/config</gen.resources.config>
</properties>
the GMavenPlus plugin
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>groooovy</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script><![CDATA[
def filePath = "${gen.resources.config}/hello.json"
println(filePath)
new File(filePath).write(output)
]]></script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- any version of Groovy \>= 1.5.0 should work here -->
<version>2.4.7</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Try the following code:
<scripts>
<script><![CDATA[
def output="test"
def filePath = "${project.basedir}/${project.properties.getProperty('gen.resources.config')}/hello.json"
println(filePath)
new File(filePath).write(output)
]]></script>
</scripts>
It's kinda the same question as this one, but the answer didn't work for me. Also I don't know how he got the output of jboss-cli in his stacktrace, that would help a lot for debugging.
Anyway I'm trying to deploy a security realm in Wildfly 10 through Maven. It works fine when doing it through the console (with the commented lines in the code below) but not with Maven Wildfly plugin.
<configuration>
<!--add security domain-->
<before-deployment>
<commands>
<!--<command>./subsystem=security/security-domain=walbangSecureRealm:add(cache-type="default")</command>-->
<!--<command>cd ./subsystem=security/security-domain=walbangSecureRealm</command>-->
<!--<command>./authentication=classic:add(login-modules=[{code="Database",flag="required",module-options={dsJndiName="java:/walbangDbDS",principalsQuery="select password from usercredential uc where uc.username = ?",rolesQuery="select role, 'Roles' from users u where u.username = ?",unauthenticatedIdentity="guest"}}])</command>-->
<command>/subsystem=security/security-domain=walbangSecureRealm:add(cache-type=default)</command>
<command>/subsystem=security/security-domain=walbangSecureRealm/authentication=classic:add(login-modules=[{"code"=>"Database","flag"=>"required","module-options"=>[("dsJndiName"=>"java:/walbangDbDS"),("principalsQuery"=>"select password from usercredential uc where uc.username = ?"),("rolesQuery"=>"select role, 'Roles' from users u where u.username = ?"),("unauthenticatedIdentity"=>"guest")]}])</command>
<command>reload</command>
</commands>
</before-deployment>
</configuration>
The error in the stacktrace is :
12:18:54,236 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "walbang-0.0.1-SNAPSHOT.war")]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit.\"walbang-0.0.1-SNAPSHOT.war\".component.ManageMatchServiceImpl.CREATE is missing [jboss.security.security-domain.walbangSecureRealm]",...
Here is more info of what I have in Maven:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
<!--wildfly plugin-->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha8</version>
<executions>
<!-- Deploy the JDBC driver -->
<execution>
<id>deploy-driver</id>
<phase>package</phase>
<configuration>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<name>mysql-connector</name>
</configuration>
<goals>
<goal>deploy-artifact</goal>
</goals>
</execution>
<!-- Add a data source -->
<execution>
<id>add-datasource</id>
<phase>package</phase>
<configuration>
<address>subsystem=datasources,data-source=java:/walbangDbDS</address>
<resources>
<resource>
<enableResource>true</enableResource>
<properties>
<connection-url>jdbc:mysql://localhost:3306/forumcs</connection-url>
<jndi-name>java:/walbangDbDS</jndi-name>
<enabled>true</enabled>
<enable>true</enable>
<user-name>root</user-name>
<password>123456</password>
<driver-name>mysql-connector</driver-name>
<use-ccm>false</use-ccm>
</properties>
</resource>
</resources>
</configuration>
<goals>
<goal>add-resource</goal>
</goals>
</execution>
<!-- Deploy the application on install -->
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<!--add security domain-->
<before-deployment>
<commands>
<!--<command>./subsystem=security/security-domain=walbangSecureRealm:add(cache-type="default")</command>-->
<!--<command>cd ./subsystem=security/security-domain=walbangSecureRealm</command>-->
<!--<command>./authentication=classic:add(login-modules=[{code="Database",flag="required",module-options={dsJndiName="java:/walbangDbDS",principalsQuery="select password from usercredential uc where uc.username = ?",rolesQuery="select role, 'Roles' from users u where u.username = ?",unauthenticatedIdentity="guest"}}])</command>-->
<command>/subsystem=security/security-domain=walbangSecureRealm:add(cache-type=default)</command>
<command>/subsystem=security/security-domain=walbangSecureRealm/authentication=classic:add(login-modules=[{"code"=>"Database","flag"=>"required","module-options"=>[("dsJndiName"=>"java:/walbangDbDS"),("principalsQuery"=>"select password from usercredential uc where uc.username = ?"),("rolesQuery"=>"select role, 'Roles' from users u where u.username = ?"),("unauthenticatedIdentity"=>"guest")]}])</command>
<command>reload</command>
</commands>
</before-deployment>
</configuration>
</plugin>
</plugins>
I want to use exec-maven-plugin to get git 'revision', so I'm using following configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>gitVersion</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>git</executable>
<workingDirectory>./</workingDirectory>
<arguments>
<argument>rev-list</argument>
<argument>master</argument>
<argument>--count</argument>
</arguments>
</configuration>
</plugin>
but I hit a problem - how do I assign output to any variable available in other plugins/livecycles?
(I was able to get it done using gmaven-plugin and executing groovy script, but I find it a bit of overkill/less elegant)
EDIT:
for reference, working solution in groovy:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>2.0</providerSelection>
<properties>
<script>git rev-list master --count</script>
</properties>
<source>
def command = project.properties.script
def process = command.execute()
process.waitFor()
def describe = process.in.text.trim()
println "setting revision to: " + describe
project.properties.setProperty('gitVersion',describe)
</source>
</configuration>
</execution>
</executions>
</plugin>
Just for clarity, here's the solution using groovy:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>2.0</providerSelection>
<properties>
<script>git rev-list master --count</script>
</properties>
<source>
def command = project.properties.script
def process = command.execute()
process.waitFor()
def describe = process.in.text.trim()
println "setting revision to: " + describe
project.properties.setProperty('gitVersion',describe)
</source>
</configuration>
</execution>
</executions>
</plugin>