Maven not honoring excludes - maven-3

We have this in our pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>app/**</exclude>
<exclude>WEB-INF/**</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>assembly-web</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>web</classifier>
<includes>
<include>app/**</include>
<include>WEB-INF/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
When I open the xxx-web.jar it looks as expected, but when I look at xxx.jar it includes everything/didn't exclude anything. If I were to add a classified to the 1st plugin (the one with the excludes) then it works properly???
I want this to work in such a way that the xxx.jar has all the class and property files and the xxx-web only has the jsp/css files.

Take a look at 7.1.6 in this maven document. Basically you need to bind to the default goal of "default-jar".
HTH

Take a look at this: Maven and working with legacy app there you will find the complete solution for your problem.

You're telling maven to execute twice with each <execution> command. Try putting the includes and excludes under the same execution.

Related

How to download multi files from swagger

I've an issue when try to download file from swagger.
When I compiled a code with config below, I got an error:
Could not find goal 'download' in plugin io.swagger:swagger-codegen-maven-plugin:2.3.1 among available goals generate
I've tried to break to 2 plugins and it compiles successfully, but just one file is downloaded.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>Addresses</api>
<owner>test</owner>
<version>2.13.0</version>
<format>yaml</format>
<token>test</token>
<outputFile>${address-service-swagger.file}</outputFile>
</configuration>
</execution>
<execution>
<id>aec</id>
<phase>generate-sources</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>Shipper</api>
<owner>test</owner>
<version>2.13.0</version>
<format>yaml</format>
<token>test</token>
<outputFile>${shipper-service-swagger.file}</outputFile>
</configuration>
</execution>
</executions>
</plugin>
By the way, I want to define outputFile is a file in the folder target, and I've tried to change outputFile by the target path, but It compiles fail. Do you have any idea for this case?
Thank you for your helps
As mentioned in the comments, to download API definitions from SwaggerHub you need to use the swaggerhub-maven-plugin, not swagger-codegen-maven-plugin.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swaggerhub-maven-plugin</artifactId>
...
</plugin>
You are using the wrong plugins and you can do like this
If your swaggerhub api link is like this https://app.swaggerhub.com/apis/massivebet/betting/0.9.0 then you config this and run
mvn clean generate-resources to download as yaml file
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swaggerhub-maven-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<api>betting</api>
<owner>massivebet</owner>
<version>0.9.0</version>
<host>api.swaggerhub.com</host>
<format>yaml</format>
<token>your token if private apis</token>-->
<outputFile>target/test.yaml</outputFile>
</configuration>
</execution>
</executions>
</plugin>

Jacoco maven plugin prepare-agent goal getting added twice

Tools :
Maven 3.2
Maven Jacoco Plugin - version 0.5.5.201112152213
Issue :
Below is the jacoco pugin included in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.5.201112152213</version>
<configuration>
<destFile>${basedir}/target/reports/jacoco.exec</destFile>
<dataFile>${basedir}/target/reports/jacoco.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
After running effective-pom , I am getting below output -
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.5.201112152213</version>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>
</executions>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</plugin>
It seems that prepare-agent goal has been included twice . The redundant goal is
<id>agent</id> which is not present in pom.xml file and haven't been added.
So , my question is : why is this goal getting included in pom even though the goal is already configured explicitly with id <id>jacoco-initialize</id>.
EDIT :
Further digging deep into problem , I removed the plugin (jacoco-maven-plugin) altogether from child module and when I run mvn help:effective-pom , interestingly it is still showing jacoco-maven-plugin with only one goal in it as below . It is the same one which gets added additionally. That means parent module is adding this plugin . But there is no reference of this plugin in parent module
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>C:\JDeveloper\mywork\myAppTest/target/coverage-reports/jacoco-unit.exec</dataFile>
<append>true</append>
</configuration>
</execution>

using swagger-codegen-maven-plugin without spring-boot dependency

I have requirement to generate rest api using swagger. I have written yaml files for generating Rest API. In my pom.xml i have
Blockquote
`<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>sample-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/swagger.yaml</inputSpec>
<output>src/test/java</output>
<language>spring</language>
<configOptions>
<sourceFolder>/</sourceFolder>
</configOptions>
<apiPackage>io.swagger.handler</apiPackage>
<modelPackage>io.swagger.model</modelPackage>
<invokerPackage>io.swagger.handler</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>`
but when i execute "mvn clean install" it asks me to provide org.springframework.boot dependency. Is there any way i can use this plugin without spring-boot dependency?
<!-- SWAGGER -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${basedir}/swagger.yaml</inputSpec>
<language>spring</language>
<output>${basedir}</output>
</configuration>
</execution>
</executions>
</plugin>

m2 release plugin couldn't recognize assembly file with parameterized name

In my POM.xml file, I am using assembly plug in. I want the build to assemble things based on the assembly file, whose name is parametrized. The build works fine. However, if I use m2 release plug in using perform release action in jenkins, the release plugin could not substitute the value for $env and pick up the assembly.xml file. I get the following exception.
Caused by: org.apache.maven.plugin.assembly.io.AssemblyReadException: Error locating assembly descriptor: src/main/assembly/${env}.xml
I have attached the log and POM file.
POM file build portion:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuraenter code heretion>
<descriptors>
<descriptor>src/main/assembly/${env}.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

maven - jibx codegen - storing binding.xml

I'm using maven to build a jar containing generated code from an schema file using jibx. To do this I'm using the jibx-maven-plugin with the schema-codegen goal. I want to include the generated binding.xml file as part of the resulting maven jar. Is there any way of directing the jar creation to include the generated binding.xml
Currently using:
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<schemaLocation>src/main/jibx</schemaLocation>
<includeSchemas>
<includeSchema>dataoneTypes.xsd</includeSchema>
</includeSchemas>
<options>
<package>org.dataone.ns.service.types.v1</package>
</options>
</configuration>
<executions>
<execution>
<goals>
<goal>schema-codegen</goal>
</goals>
</execution>
</executions>
</plugin>
David,
Good! While including the binding.xml file is not required, it is good practice. The new jibx-maven-plugin can use this file later when creating a new binding that is based on the original schema. There are plenty of examples in the JiBX source repository.
Since JiBX is OSGi enabled, it is also good practice to add an OSGi manifest when creating your jar file. This also simplifies including the binding.xml file. Even if you don't use OSGi, your jar will work fine. Here is what your project file should look like:
<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>org.dataone.ns.service</groupId>
<artifactId>org.dataone.ns.service.types.v1</artifactId>
<version>0.0.1</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/jibx</schemaLocation>
<includeSchemas>
<includeSchema>dataoneTypes.xsd</includeSchema>
</includeSchemas>
<options>
<package>org.dataone.ns.service.types.v1</package>
</options>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<goals>
<goal>bind</goal>
</goals>
<configuration>
<schemaBindingDirectory>target/generated-sources</schemaBindingDirectory>
<includes>
<include>binding.xml</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>META-INF/binding.xml=${basedir}/target/generated-sources/binding.xml</Include-Resource>
<Export-Package>org.dataone.ns.service.types.v1.*;version=${project.version}</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-run</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-extras</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
Take a look at your jar file. Your classes, the binding.xml file, and OSGi manifest entries are there!
Don Corley
jibx-maven-plugin author
You can always use maven-antrun-plugin to copy your file(set) to target/classes.
Make sure that:
you attach the jibx plugin to a phase before package - best is generate-resources
you attach the antrun execution to the same or later, but again, before package - best is generate-resources or process-resources
the jibx plugin declaration precedes antrun declaration
Then you can use something like this:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="${project.build.directory}/PATH/TO/binding.xml" todir="${project.build.outputDirectory}/PATH/IN/JAR/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
...
You can create your binding.xml in the target directory you want it to be placed in the jar like this:
...
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
...
<targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
When binding the code, you can use the refer to this directory with the <bindingDirectory> tag
You can do it using the add-resource goal of the build-helper-maven-plugin.
Example:
<build>
<plugins>
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<id>generate-java-code-from-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<schemaLocation>src/main/resources</schemaLocation>
<includeSchemas>
<includeSchema>foobar.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
<execution>
<id>compile-binding</id>
<phase>process-classes</phase>
<goals>
<goal>bind</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.build.directory}/generated-sources</directory>
<includes>
<include>binding.xml</include>
</includes>
<targetPath>JiBX</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
You will find the binding.xml file in your jar at:
JiBX/binding.xml

Resources