How to address "The parameters 'tags' are missing or invalid:" error while running my runner class using maven command "mvn test"? - maven

I am getting this error when I am trying to run the runner class by using mvn test command:
[ERROR] Failed to execute goal com.github.temyers:cucumber-jvm-parallel-plugin:5.0.0:generateRunners (generateRunners) on project Demo_Automation: Invalid parameter. : Invalid parameter.
[ERROR] The parameters 'tags' are missing or invalid: [null]
I kept both my runner class and stepdefinitions in same folder:
src/test/java/setpfiles/runnerclass.java & stepdefinitionfiles
I added the required plugins and dependencies in my pom file but still facing the error.
These are the plugins in pom.xml
'<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>4.1.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>
<package>aaa_stepFiles</package>
</glue>
<outputDirectory>src/test/java/aaa_testcases</outputDirectory>
<featuresDirectory>src/test/resources/aaa_FeatureFiles</featuresDirectory>
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<plugins>
<plugin>
<name>json</name>
<extension>json</extension>
<outputDirectory>${project.build.directory}/cucumber-parallel/json</outputDirectory>
</plugin>
</plugins>
<strict>true</strict>
<monochrome>true</monochrome>
<tags>
<tag>${Scenario}</tag>
</tags>
<useTestNG>false</useTestNG>
<namingScheme>simple</namingScheme>
<namingPattern>Parallel{c}Test</namingPattern>
<parallelScheme>SCENARIO</parallelScheme>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>'

Ensure that both the files:
runnerclass.java
stepdefinitionfiles
both are within /src/test.java
Additionally, within #CucumberOptions pass the location of the feature file as follows:
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/resources/AppFeatures/Order.feature"},
glue = {"stepdefinations"},
plugin = {"pretty"}
)

Related

How can I compile a project that implements interfaces in generated sources folder from openapi generator?

I am using the OpenAPI generator maven plugin with kotlin-spring generator to generate interfaces for my API based on the specification.
As an example, I used the specification by this blog post and the following plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>*
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/petstore.yml
</inputSpec>
<generatorName>kotlin-spring</generatorName>
<modelNameSuffix>Dto</modelNameSuffix>
<configOptions>
<basePackage>com.example</basePackage>
<apiPackage>com.example.api</apiPackage>
<modelPackage>com.example.model</modelPackage>
<configPackage>com.example.config</configPackage>
<delegatePattern>true</delegatePattern>
<interfaceOnly>true</interfaceOnly>
<supportingFilesToGenerate>
ApiUtil.kt
</supportingFilesToGenerate>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
When I run mvn clean generate-sources then the files are properly generated in target/generated-sources/openapi/....
I then create an implementation of the delegate in my src folder where I can override the methods of the generated interface:
package com.example.api
class PetsApiDelegateImpl : PetsApiDelegate {
}
Up to now, everything is good and IntelliJ is also happy with it. However, when I run mvn clean compile the target folder is deleted and re-generated again as expected but I still receive an error:
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.5.31:compile (compile) on project choreographer: Compilation failure
[ERROR] /path/to/example/src/main/kotlin/com/example/api/PetsApiDelegateImpl.kt:[3,29] Unresolved reference: PetsApiDelegate
In other words, the files are generated as part of mvn clean compile but compilation still fails because the interface is not found.
How can I successfully compile this project?
We can resolve the compilation failure by adding an execution for the compile goal to the kotlin-maven-plugin that configures the generated directory as source directory.
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.build.directory}/generated-sources/kotlin/src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>

Mapstruct - cannot find symbol [Kotlin + Maven]

I'm having the following error when I run the command mvn clean install:
[ERROR] /Users/xxx/xxx/xxx/xxx.xxx/target/generated-sources/kapt/compile/com/xxx/xxx/xxx/xxx/DataMapperImpl.java:[10,40] cannot find symbol
[ERROR] symbol: class DataMapperDecorator
[ERROR] /Users/xxx/xxx/xxx/xxx.xxx/target/generated-sources/kapt/compile/com/xxx/xxx/xxx/xxx/DataMapperImpl.java:[10,74] cannot find symbol
[ERROR] symbol: class DataMapper
[ERROR] /Users/xxx/xxx/xxx/xxx.xxx/xxx/generated-sources/kapt/compile/com/xxx/xxx/xxx/api/DataMapperImpl.java:[12,19] cannot find symbol
[ERROR] symbol: class DataMapper
[ERROR] location: class com.xxx.xxx.xxx.xxx.DataMapperImpl
It seems that after mapstruct has generated the DataMapperImpl.java class it is not able to find the classes DataMapper and DataMapperDecoretor.
The code related to mapstruct is in a xxx.kt file:
//Other stuff
...
#Mapper
#DecoratedWith(DataMapperDecorator::class)
interface DataMapper {
#Mappings(
Mapping(source = "data.value", target = "dataValue"),
Mapping(source = "data.current.value", target = "currentValue"),
)
fun toDto(data: Data) : RefDataDto
}
abstract class DataMapperDecorator : DataMapper {
#Autowired
private val delegate: DataMapper? = null
override fun toDto(data: Data): dataDto {
val dataDto = delegate!!.toDto(data)
dataDto.primaryValue = data.primaryValue?.let { CurrencyUtil.toMajor(it) }
return dataDto
}
}
Regarding the pom files I have in the root file:
...
<properties>
...
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
</properties>
...
and this is the pom of the module where I'm using mapstruct:
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
I hid some part of the files with dots and I'm not using the project Lombok (I saw same problems related with it we you are trying to use these projects together).
UPDATE 1:
I noticed that the error is related to the fact that from the generated class DataMapperImpl.java the package where there are the classes that this generated class should use is not visible. Indeed I see this error:
[ERROR] /Users/xxx/xxx/xxx/xxx.xxx/xxx/generated-sources/kapt/compile/com/xxx/xxx/xxx/xxx/RefDataMapperImpl.java:[3,47] package com.my.package.application.domain does not exist
and of course this package exist!
UPDATE 2:
I'm continuing to investigate on this issue. I tried to make it simpler deleting the DataMapperDecorator and put the DataMapper, the Data and the DataDto class in the same file. Still the same error cannot find symbol: class for all the three classes. I'm not sure if this is related to the fact that in the DataMapperImpl (the generated class) doesn't have the import of these classes. There are imports just for the standard java libraries such as:
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.UUID;
import javax.annotation.processing.Generated;
EDIT 1:
From the log I can also see the following warning:
[WARNING] 'tools.jar' was not found, kapt may work unreliably
UPDATE 3:
Without mapstruct under target->classes (using IntelliJ IDEA) I can see the classes of my project. On the other hand when I have introduced mapstruct what I'm seeing is that the mapstruct classes are generated under target->generated-sources->kapt->compile but under target->classes I don't see the other classes. Could the mapstruct classes be generated earlier than the other classes of my project causing the compiler to not find the Data, DataDto classes?
SOLVED!
The problem was due to the order of the compilation. By default the java compiler is executed before the kotlin compiler. That why the code generated by mapstruct wasn't able to find the kotlin classes. So it is needed to compiler the koltin classes before and then the java classes.
"The idea is to disable default compile execution and introduce our own to get control over the order in which goals are executed, so that we could run kotlin compiler before java compiler."
https://discuss.kotlinlang.org/t/maven-compiler-plugin-question/5260/4
So the solution came introducing the maven plugin:
https://kotlinlang.org/docs/maven.html#compile-kotlin-and-java-sources
So I added this to my pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
I am not sure how Kotlin works with multiple classes in one source file.
What I would suggest is that you use dedicated files for the decorator and the mapper. That way MapStruct will create the correct code.
MapStruct is a Java annotation processor, we do not know anything about the Kotlin structure. It seems like the packages returned by the java annotation processing API are not correct.
Addition to #SGiux answer. The order of plugins in pom also matters:
kotlin-maven-plugin
maven-compiler-plugin

Generating Javadoc in Maven does give errors because of proxy

I'm trying to generate my javadoc using Maven to use in SpringFox Swagger.
When I generate the Javadoc using Maven I got an error like:
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.0:javadoc (default) on project Spring-server: An error has occurred in Javadoc report generation:
Exit code: 1 - javadoc: error - Illegal package name: "!"
Command line was: "C:\Program Files\Java\jdk1.8.0_162\jre\..\bin\javadoc.exe" -J-Dhttp.proxySet=true -J-Dhttp.proxyHost=10.5.5.5 -J-Dhttp.proxyPort=8080 "-J-Dhttp.nonProxyHosts=\"tst*\"" "-J-Dhttp.proxyUser=\"user\"" "-J-Dhttp.proxyPassword=\"pw with space !\"" #options #packages
How can I disable the proxy for generating Javadoc? I need the proxy to download all the dependencies but for generating the Javadoc itself it should not use any Proxy. So is it possible to disable the proxy for the javadoc maven Plugin?
My Maven javadoc settings looks like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
<executions>
<execution>
<goals>
<goal>javadoc</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<doclet>springfox.javadoc.doclet.SwaggerPropertiesDoclet</doclet>
<docletArtifact>
<groupId>io.springfox</groupId>
<artifactId>springfox-javadoc</artifactId>
<version>0.9.3</version>
</docletArtifact>
<additionalparam>
-classdir ${project.build.outputDirectory}
</additionalparam>
<sourcepath>${project.build.sourceDirectory}</sourcepath>
<subpackages>com.atlascopco.ilm2</subpackages>
<useStandardDocletOptions>false</useStandardDocletOptions>
</configuration>
</execution>
</executions>
</plugin>

Maven liquibase plugin change log file

Using liquibase-maven-plugin inside a project :
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>some maven phase</phase>
<configuration>
<changeLogFile>liquibase/changeLogFile.xml</changeLogFile>
<!-- other configurations -->
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
The changeLogFile is in /src/main/resources/liquibase.
It works when bound to any phase in the range validate - prepare-package.
When bound to a later phase, i.e. package - deploy, it fails with the error :
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default) on project ...: Error setting up or running Liquibase: liquibase/changeLogFile.xml does not exist
It will find the changeLog file if the path is specified as src/main/resources/liquibase/changeLogFile.xml but that's beside the point.
Why binding the plugin to a later phase makes it fail ?

What is the format for specifying a package in the Antlr4 maven plugin?

What is the format for specifying a package in the Antlr4 maven plugin antlr4-maven-plugin?
I feel like I should be able to do the following:
<plugin>
<groupId>com.tunnelvisionlabs</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<arguments>package my.package.name</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
but that results in the following error:
[ERROR] Failed to execute goal com.tunnelvisionlabs:antlr4-maven-plugin:4.0:antlr4 (default) on project my_project: Unable to parse configuration of mojo com.tunnelvisionlabs:antlr4-maven-plugin:4.0:antlr4 for parameter arguments: Cannot assign configuration entry 'arguments' with value 'package my.package.name' of type java.lang.String to property of type java.util.List -> [Help 1]
If I am you, I will make a maven project per package and try this
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<sourceDirectory>${basedir}/src</sourceDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
but usually, When I pass an argument in maven configuration, I do the following. but I am not sure of that syntax in antlr4
<plugin>
<groupId>com.tunnelvisionlabs</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<arguments>
<argument>-package</argument>
<argument>my.package.name</argument>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
Edit: Notice the - in front of package so the antlr-maven-plugin will recognize it as a parameter
The package is automatically determined based on the location of the file in your project, similar to the way the package is determined for Java files. The output is also placed in a location determined by the location of the source file. To change the package where the code is generated, you'll need to move the grammar file.
Other arguments can be specified like this:
<arguments>
<argument>arg1</argument>
<argument>arg2</argument>
</arguments>
Your configuration arguments syntax is wrong.
Please change the configuration of antlr4-maven-plugin from
<configuration>
<arguments>package my.package.name</arguments>
</configuration>
to:
<configuration>
<arguments>
<argument>-package</argument>
<argument>my.package.name</argument>
</arguments>
</configuration>
In order to add package information to the generated code you must add the following annotation to the g4 file:
#header {
package com.this.is.my.package;
}
I tried
#header {
package com.this.is.my.package;
}
but when you have imports it adds package line for each file imported and as a result compiler errors raised in generated file. You have to be careful to add #header so file with imported grammars had only one package line. I think it's a bug.
I have the Demo.g4 inside src/main/antlr4/de/schmitz.
Now the classes are generated to target/generated-sources/antlr4/de/schmitz.
The package is de.schmitz.
Everything is correct.
Now I want to change the package and folders of the generated classes (actually NOT moving my Demo.g4):
<arguments>
<argument>-package</argument>
<argument>my.package</argument>
</arguments>
The classes are generated to target/generated-sources/antlr4/de/schmitz.
The package is my.package.
This cannot be compiled, so it could be an error.
So I want to change the output directory:
<outputDirectory>${project.build.directory}/generated-sources/antlr4/my/package</outputDirectory>
Now it get's buggy.
The package is my.package.
But the folder is target/generated-sources/antlr4/my/package/de/schmitz.
So it's concatenated instead of overwritten.

Resources