Issue generating Pact files using PactContractConverter - pact

I'm trying to generate the pact files as specified here so I can verify the results to my broker.
Version: spring cloud 2.2.2 & Pact JVM 3.5.23.
I've configured the plugin as shown below...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>convert-dsl-to-pact</id>
<phase>process-test-classes</phase>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer</mainClass>
<arguments>
<argument>org.springframework.cloud.contract.verifier.spec.pact.PactContractConverter</argument>
<argument>${project.basedir}/target/pacts</argument>
<argument>${project.basedir}/target/generated-test-sources/contracts</argument>
</arguments>
</configuration>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
I get the following error...
[INFO] --- exec-maven-plugin:1.6.0:java (convert-dsl-to-pact) # employee ---
...
10:55:24.349 [org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer.main()] WARN org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter - Exception occurred while trying to parse the file [/Users/luke/workspaces/dbs/employee/employee-service/employee/target/generated-test-sources/contracts/com/backbase/dbs/employee/contract/com/backbase/dbs/employee/employee_serviceagreements_get_api_producer_pact/ContractsTest.java] as a contract. Will not parse it.
java.lang.IllegalStateException: Class with name [ContractsTest] not found
at org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter.classConstructor(ContractVerifierDslConverter.groovy:166)
at org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter.parseJavaFile(ContractVerifierDslConverter.groovy:144)
at org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter.toObject(ContractVerifierDslConverter.groovy:131)
at org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter.convertAsCollection(ContractVerifierDslConverter.groovy:98)
at org.springframework.cloud.contract.verifier.util.ContractScanner$1.visitFile(ContractScanner.groovy:88)
at org.springframework.cloud.contract.verifier.util.ContractScanner$1.visitFile(ContractScanner.groovy)
at java.nio.file.Files.walkFileTree(Files.java:2670)
at java.nio.file.Files.walkFileTree(Files.java:2742)
at org.springframework.cloud.contract.verifier.util.ContractScanner.collectContractDescriptors(ContractScanner.groovy:77)
at org.springframework.cloud.contract.verifier.util.ContractScanner.collectContractDescriptors(ContractScanner.groovy:59)
at org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer.storeContractsAsFiles(ToFileContractsTransformer.groovy:75)
at org.springframework.cloud.contract.verifier.util.ToFileContractsTransformer.main(ToFileContractsTransformer.groovy:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.lang.Thread.run(Thread.java:748)
The generated sources and generated tests seem to be in the correct place.
Any ideas?

Related

JavaFX access internal webkit document

I am trying to access javafx.web/com.sun.webkit.dom from my unnamed module javafx project. For this, I have created a class com.sun.webkit.dom.DomMapper.
I do not see any error in the IDE, but when I run it using mvn clean javafx:run it complains -
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sun/webkit/dom/DomMapper
....
Caused by: java.lang.ClassNotFoundException: com.sun.webkit.dom.DomMapper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
...
This is how my pom.xml looks
<?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> ... </groupId>
<artifactId> ... </artifactId>
<version> ... </version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<exec.mainClass> .... </exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<options>
<option>--add-exports</option><option>javafx.web/com.sun.webkit.dom=ALL-UNAMED</option>
<option>--add-opens</option><option>javafx.web/com.sun.webkit.dom=ALL-UNAMED</option>
</options>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>--add-exports</arg><arg>javafx.web/com.sun.webkit.dom=ALL-UNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
If I use the Maven shade plugin, I am able to bypass this issue.
I think it has got to do with how JPMS security works, but I cannot figure out how to bypass this. I tried add-exports, and add-opens in various combinations, but it did not help me.
What am I doing wrong?
BTW, I want to map the WebKit DOM to the JSoup dom element, as they give a nice API for CSS selectors.
Update
I am adding an additional stack trace of the error
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: com/sun/webkit/dom/DomMapper
at xyz.jphil.internal_browser.TestApp.start(TestApp.java:86)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.webkit.dom.DomMapper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 10 more
The solution for this problem lies in using using --patch-module. As I have added a class - com.sun.webkit.dom.DomMapper which is completely sealed by JPMS. The reason why I added DomMapper in the com.sun.webkit.dom.DomMapper was to access some package-private functions.
However, I see that can be easily avoided so I am choosing to avoid using those package-private functions. With this --patch-module is not required, which is also not a recommended thing to do as per JPMS documentation. Now the solution is simpler. Adding --add exports is enough (which is already there in the POM) and I am able to get it working.
Finally exporting the entire program as a farjar using maven shade plugin for example, also works. This I am adding just for information.
This answer is based on comments and valuable inputs by Jewelsea and Slaw.
Further notes:
This example shows the public (although internal) functions of the com.sun.webkit.dom are quite good as it is, gist.github.com/jewelsea/6722397
The problem I created by making a class inside com.sun.webkit.dom is called split-package - read here How split packages are avoided in Java 9

Schema Class Generations Failing with XMLBeans version 5.0.1 and xmlbeans-maven-plugin 5.0.1

While generating classes using below new xmlbeans-maven-plugin 5.0.1, i am getting exception
<plugin>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>5.0.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDir>${basedir}/xsd</sourceDir>
<javaTargetDir>src/main/java</javaTargetDir>
<debug>true</debug>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
</dependencies>
</plugin>
Exception:
Cannot find symbol: class XMLInputStream
[exec] location: package org.apache.xmlbeans.xml.stream
Cannot find symbol: symbol: class XMLStreamException
[exec] location: package org.apache.xmlbeans.xml.stream
I know this issue occurs because the new xmlbeans 5.0.1 doesnt have the 2 classes mentioned above. But i want to upgrade to latest xmlbeans version and also used the latest maven-plugin provided by xmlbeans.
Still facing the issue.
Could anyone help me to solve this issue?
You should add extentions part in configuration.
<configuration>
...
<repackage>com.xxx.yyy.metadata</repackage>
<name>pgmessages</name>
<partialMethods>ALL,-GET_LIST,-XGET_LIST,-XGET_ARRAY</partialMethods>
<extensions>
<extension>
<className>org.apache.xmlbeans.impl.tool.Extension</className>
</extension>
</extensions>
</configuration>

Maven verify doesn't execute Cucumber-Serenity integration tests with fail-safe

I have below POM in my project.
mvn clean verify -P it
POM:
<build>
<pluginManagement>
<plugins>
.....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-plugin.version}</version>
<configuration>
<skipTests>false</skipTests>
<excludes>
<exclude>**/*CucumberTests.java</exclude>
<exclude>**/IT*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-plugin.version}</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*CucumberTests.java</include>
<include>**/*IT.java</include>
</includes>
<systemPropertyVariables>
<it.server.port>${random.http.port}</it.server.port>
<it.jmx.port>${random.jmx.port}</it.jmx.port>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<skip>false</skip>
<wait>2000</wait>
<!-- Max retry count -->
<maxAttempts>180</maxAttempts>
<jmxPort>${random.jmx.port}</jmxPort>
<arguments>
<argument>--server.port=${random.http.port}</argument>
<argument>--spring.profiles.active=${spring.profile}</argument>
</arguments>
<jvmArguments>
-Djava.security.egd=file:///dev/urandom
</jvmArguments>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<skip>false</skip>
<jmxPort>${random.jmx.port}</jmxPort>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
...
</plugin>
</plugins>
</build>
Test class:
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
plugin = {"pretty"},
glue = {"my.stepdefinitions"},
tags = {"#Demo"},
features = "src/it/resources/features/"
)
public class MicroServiceCucumberTests {
}
path: src/it/java
Basically it trigger sure-fire and then startup the app and just stuck there without executing maven-failsafe-plugin:2.21.0:integration-test (integration-tests)
Versions are being used:
<serenity.plugin.version>2.4.34</serenity.plugin.version>
<serenity.version>2.4.34</serenity.version>
<serenity.cucumber.version>2.4.34</serenity.cucumber.version>
<cucumber.version>6.10.4</cucumber.version>
<maven-plugin.version>3.0.0-M5</maven-plugin.version>
<java.version>1.8</java.version>
After digging further into logs what I noticed was, app didn't start up properly and stuck with below logs
DEBUG] Application argument(s): --server.port=54110 --spring.profiles.active=it
[DEBUG] Connecting to local MBeanServer at port 54111
[DEBUG] Waiting for spring application to start...
[DEBUG] MBean server at port 54111 is not up yet...
[DEBUG] Spring application is not ready yet, waiting 2000ms (attempt 1)
[DEBUG] MBean server at port 54111 is not up yet...
[DEBUG] Spring application is not ready yet, waiting 2000ms (attempt 2)
This solution worked for me https://stackoverflow.com/a/65952986/2303693
Adding below within the spring-boot-maven-plugin in the POM did the trick.
<configuration>
<fork>false</fork>
</configuration>
However same code worked in iOS machine without above fix. Further still not sure what caused the issue in Windows.

When using Maven Assembly Plugin - Manifest.MF is not packaged in the correct order

Failed to install artifact: C:\Test\7\config\analyzers\analyzers-7.0.0-13-SNAPSHOT-jar-with-dependencies.jar: org.osgi.framework.BundleException: The bundle file:/C:/Test/7/config/analyzers/analyzers-7.0.0-13-SNAPSHOT-jar-with-dependencies.jar does not have a META-INF/MANIFEST.MF! Make sure, META-INF and MANIFEST.MF are the first 2 entries in your JAR!
org.osgi.framework.BundleException: The bundle file:/C:/Palamida/7.0-v4/config/analyzers/analyzers-7.0.0-13-SNAPSHOT-jar-with-dependencies.jar does not have a META-INF/MANIFEST.MF! Make sure, META-INF and MANIFEST.MF are the first 2 entries in your JAR!
at org.apache.felix.fileinstall.internal.DirectoryWatcher.installOrUpdateBundle(DirectoryWatcher.java:1004)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:952)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:871)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:485)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)
The 1st part of the error claims there is no MANIFEST.MF but checking manually reveals it is there. The 2nd part of the error claims the MANIFEST.MF is not one of the 1st two entries in the jar which I have not been able to verify. Is there a configuration issue with my assembly plugin?
My pom.xml containing my maven-assembly-plugin config:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
I am also using maven-bundle-plugin with the manifest goal, which outputs a manifest.mf which is consumed by assembly-plugin, but I don't believe that should be causing any interference.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<finalName>${name.project}</finalName>
<archive>
<manifest>
<mainClass>br.com.car.view</mainClass>
</manifest>
<manifestFile>${basedir}/META-INF/MANIFEST.MF</manifestFile>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Way to use manifest command File in your maven (pom) configuration file

Error reading assemblies: No assembly descriptors found

I get Error reading assemblies: No assembly descriptors found when building my project. I'm trying to set permissions for my .sh files and exclude a nasty .jar file that makes my application crash...I don't think the problem is about that though....
My maven-assembly plugin is added like this in my pom.xml file:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/src.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
My assembly descriptor looks like this:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>my-assembly-descriptor</id>
<formats>
<format>jar</format>
<format>war</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<excludes>
<exclude>spring-2.5.4.jar</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
The structure in my project is:
Interface - src - main - assembly - src.xml
- pom.xml
When trying to do Run as -> Debug as -> and then in goal putting
assembly:single
I get the same error. I tried in console, with assembly:assembly, and I got nothing. I even tried to put a wrong path to my assembly descriptor, but the error didn't change. When putting ${basedir}/ before the path to my assembly descriptor, I get the same.
I have Ubuntu 10.10 Maverick Meerkat, and I'm working with Eclipse EE,...
Thanks!
I have been using version 2.3 of maven-assembly-plugin, but I believe the problem is the same: if the assembly configuration is declared inside an execution, it works from mvn package, but does not work from mvn assembly:assembly.
The solution I have found is to declare the configuration in the top-level configuration of the plugin, and keep the execution as small as possible:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/standalone.xml</descriptor>
</descriptors>
<finalName>standalone</finalName>
</configuration>
<executions>
<execution>
<id>standalone</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
It seems that you have configured the assembly plugin in <build>...<pluginManagement>...<plugins>. It should work if you configure the plugin in <build>...<plugins>.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/src.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I was also facing the same issue with below command
$mvn clean assembly:single
But below command worked for me
$mvn clean assembly:assembly

Resources