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>
Related
I am using <dateLibrary>java11-localdatetime</dateLibrary> but it is generating the code with java.util.Date and ignoring the data type format: date-time.
I have to use typeMapping to replace the 'util date' to LocalDate as shown in the below
configuration:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.27</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/spec.yaml</inputSpec>
<language>spring</language>
<output>${project.basedir}</output>
<modelPackage>com.generated.model</modelPackage>
<apiPackage>com.generated.api</apiPackage>
<generateModels>true</generateModels>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApis>true</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<dateLibrary>java11-localdatetime</dateLibrary>
</configOptions>
<importMappings>
<importMapping>Date=java.time.LocalDate</importMapping>
</importMappings>
<typeMappings>
<typeMapping>Date=LocalDate</typeMapping>
</typeMappings>
</configuration>
</execution>
</executions>
</plugin>
This has been resolved by using the following configurations:
<configOptions>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<dateLibrary>java8-localdatetime</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<defaultInterfaces>false</defaultInterfaces>
</configOptions>
Useful links:
swagger-codegen default interface
i am using junit5 with springboot 2.4.4 version. I have integrated jacoco for the test coverage. However my test gets passed but coverage is not shown in it.
Here i am mention a demo class of the concept what i am implemented
public class Calculator {
public int sum() {
return sumPrivate();
}
private int sumPrivate() {
return 100;
}
}
And this is test class of it
public class CalculatorTest {
#Test
public void test() {
assertNotNull(new Calculator().sum());
}
}
i have debugged my class private method gets called but not shown in jacoco code coverage.
And here is my plugin configuration
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>unit-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${maven.test.skip}</skip>
<argLine>${argLine}</argLine>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skipITs}</skip>
<argLine>${argLine}</argLine>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<skip>${maven.test.skip}</skip>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<output>file</output>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
I am still facing this issue right now. I used spring-boot-maven-plugin and some of the classes were coverage were detected. But still it is not a solution!
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>${argLine}</jvmArguments>
</configuration>
<executions>
<execution>
<id>start-spring-boot</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-spring-boot</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
You need to specify goal check after test in-order to check coverage.
If you also need to generate report then goal is report
Here are all the possible goals. Got to the end of page.
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>coverage-validation</id>
<goals>
<goal>check</goal>
</goals>
<phase>test</phase>
<configuration>
<rules>
<rule>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.90</minimum>
</limit>
</limits>
</rule>
</rules>
<haltOnFailure>true</haltOnFailure>
</configuration>
</execution>
</executions>
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>
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>
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>