How to configure suppress ParameterNumber on checkstyle? - checkstyle

How to configure to suppress the number of parameter (ParameterNumber) on checkstyle:
Checkstyle configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>9.1</version>
</dependency>
</dependencies>
<configuration>
<configLocation>/config/checkstyle.xml</configLocation>
<suppressionsLocation>/config/checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
checkstyle-suppressions.xml file:
<suppressions>
<suppress checks="ParameterNumber" files="src/main/java/org/acme/Signal.java" />
</suppressions>
I still got the message:
Signal.java:[247,26] (sizes) ParameterNumber: More than 7 parameters (found 15).

https://checkstyle.sourceforge.io/config_filters.html#SuppressionFilter
Location of the file defined in file property is checked in the
following order:
as a filesystem location
if no file found, and the location starts with either http:// or https://, then it is interpreted as a URL
if no file found, then passed to the ClassLoader.getResource() method.
Use the package exactly is in java:
<suppress
checks="ParameterNumber"
files="org.acme.Signal.java" />

Related

Trying to generate class from xsd located in dependencies

For my project, I need to get xsd schemas that are kept in another project and generate my classes using maven-jaxb2-plugin. I am trying to get these Shema through my dependency (integration-pubsub-global-config), but I keep getting errors : [ERROR] Error while parsing schema(s).Location []. Here is my configuration for the plugin :
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.2</version>
<executions>
<execution>
<id>generate-sources-message</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<extension>true</extension>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
<bindingDirectory>${basedir}/src/main/jaxws</bindingDirectory>
<bindingIncludes>
<include>bindings.xml</include>
</bindingIncludes>
<schemas>
<schema>
<dependencyResource>
<groupId>com.XXXXX.YYYYYY-YYYY.integration</groupId>
<artifactId>integration-pubsub-global-config</artifactId>
<resource>src/export/pubsub-xsd-contracts/SM840-IntegrationEvenements/Donnees/Event/EventV3.xsd</resource>
</dependencyResource>
</schema>
</schemas>
<generateDirectory>${cxf.generated.sources.folder}</generateDirectory>
<enableIntrospection>true</enableIntrospection>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.5.3</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>

Unable to suppress excessive logs from scalatest-maven-plugin

Background
I am facing excessive logging from default Logger when I run scala tests from maven because it is not picking up the logback.xml on the classpath with the correct logging definitions
So my maven config is fairly generic (as per scalatest-maven-plugin docs)
Looks like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>MyProj_TestSuite.txt</filereports>
<forkMode>never</forkMode>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
I have a logback.xml in my src/main/resources which gets copied over to target/classes
Things I tried so far
Have spent a whole day to figure out why this is not being picked up -- using the following configuration optional entries
<runpath>
${project.basedir}/target/classes
</runpath>
<systemProperties>
<logback.configurationFile> ${project.basedir}/src/main/resources/logback.xml</logback.configurationFile>
</systemProperties>
<argLine>
-Dlogback.configurationFile=src/main/resources/logback.xml
</argLine>
If I run it like this (from command line) from ${project.basedir}
mvn test -Dlogback.configurationFile=./src/test/resources/logback.xml
it works
I have looked at similar issues on stack and even tried adding this
<build>
<testResources>
<testResource>
<directory>${project.basedir}/target/classes</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
This did not work - I think it is because I am using scala-maven-test plugin which has its own configuration block.
Any help on how to do this from inside the pom.xml will be much appreciated.
Try to have /src/test/resources/logback-test.xml logback configuration file.
It works for me with scalatest-maven-plugin of 2.0.2 version.

Generate code for multiple swaggers in the same project

How do i generate code for multiple swagger files from within the same module/project in one pom.xml.
In my application client had provided a swagger and we have one of the backend API to be called for which they provided swagger. I want to generate code for both of these in the same project. One way i was thinking is create separate module and execute the plugin separately and have those dependencies called out in main module.
How do i generate code from one build plugin? Please point me to existing one if it is a repost. I couldn't find any.
Here is the plugin i configured in pom.xml
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/ resources/Service.json</inputSpec><inputSpec>${project.basedir}/src /main/resources/Client.json</inputSpec>
<language>java</language>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<modelPackage>com.service.model</modelPackage>
<environmentVariables>
<models/>
<supportingFiles>false</supportingFiles>
</environmentVariables>
</configuration>
</execution>
</executions>
</plugin>
Also tried *.json. At anytime it is taking only one json file and generating the code.
In order to do this you could declare a different execution for each json file, each one should have a unique id.
Here is an example with two executions, execution-first-json for the file first.json and execution-second-json for the file second.json
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>execution-first-json</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/first.json</inputSpec>
<language>java</language>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<modelPackage>com.service.model</modelPackage>
<environmentVariables>
<models/>
<supportingFiles>false</supportingFiles>
</environmentVariables>
</configuration>
</execution>
<execution>
<id>execution-second-json</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/second.json</inputSpec>
<language>java</language>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<modelPackage>com.service.model</modelPackage>
<environmentVariables>
<models/>
<supportingFiles>false</supportingFiles>
</environmentVariables>
</configuration>
</execution>
</executions>
</plugin>

maven-jaxb2-plugin ignoring configuration

I'm using maven 3.3.9 and the maven-jaxb2-plugin 0.13.1. But when I try to generate the Java classes, the plugin is not finding my XSD-file.
My pom looks like this:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/schemas</schemaDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Everytime I'm executing the goal, I get this message:
[WARNING] No schemas to compile. Skipping XJC execution.
The directory exists under the resources folder, and the XSD is placed there. I have no other pom-files in play.
Any help would be very much appreciated
In case anyone else will hit this. I had a similar issue: the configuration was not picked up by the plugin. I made it work by moving configuration section under plugin declaration instead of execution.
Here's how the working configuration looked like for me (I removed the upper-level elements since they do not matter):
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.15.1</version>
<configuration>
<schemaDirectory>src/main/resources/custom-schemas</schemaDirectory>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
/executions>
</plugin>
Author of maven-jaxb2-plugin here.
Somehow I have a feeling that you're omitting important details. This does not not add up. This is a very basic configuration setting, I'm curious how it can't work.
You only post the pluginManagement part of your pom.xml. If you have just this, it should not work at all as it is just and only a declaration of configuration, not actual usage of the plugin. You need plugins/plugin to actually apply the plugin:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
To analyze the problem, run mvn -X clean generate-sources or mvn -X clean install and check the applied configuration (it will be logged). Post the log here.
If this does not help, send me a PR of a minimal reproducing project under https://github.com/highsource/maven-jaxb2-plugin-support/s/schemaDirectory, I'll take a look.

IntelliJ Error when running unit test: Could not find or load main class ${surefireArgLine}

I get the following error when running Unit tests in IntelliJ:
Error: Could not find or load main class ${surefireArgLine}.
I am using maven and in pom.xml I have:
<properties>
...
<surefire.argLine />
</properties>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<!--Sets the VM argument line used when unit tests are run.-->
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!--Sets the path to the file which contains the execution data.-->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
...
Did anyone have similiar problem? How to set value for surefireArgLine?
I had the same problem and i think i found the solution on the vertx-issue tracker.
In short you have to configure your IntelliJ Maven (surefire plugin) integration to behave differently.
This works for me in IntelliJ 14.1.6 with mvn 3.3.9
Preferences -> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
For IntelliJ 2019 and above
Settings-> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
Uncheck argLine
I was able to fix this error in Netbeans by changing the surefire-plugin version to 2.10 and removing
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
from the maven-surefire-plugin configuration. Instead i have created a property argLine that is picked automatically by surefire.
<properties>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
Now, i can run and debug single files and test methods. And Code Coverage is working as expected.
Update of pom.xml solved my problem.
<argLine>${surefire.argLine}</argLine>
Complete plugin info in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<workingDirectory>${project.build.directory}</workingDirectory>
<jvm>${env.JDK1_8_HOME}\bin\java</jvm>
<argLine>${surefire.argLine}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin> -->
Was looking for this and found this project "fix" it in this thread
Basically define your jacocoArgLine var name as empty project property. Then in surefire configuration use #{jacocoArgLine} instead of dollar prefix.
I found out that I have to run my test case from maven with
mvn -Dtest=TestCircle test
not directly from IDE.
For a more permanent fix for every new project add the following to your IntelliJ IDEA Custom VM Options:
Help > Edit Custom VM options
Add: -Didea.maven.surefire.disable.argLine=true
This will deactivate surefire for all new projects you open.