yuicompressor-maven-plugin not bounded to process-resources - maven-2

I have been trying to figure out why yuicompressor-maven-plugin is not executed during "mvn package". I can execute it in an independent task as described in the link below but somehow the plugin does not get called from maven life cycle.
http://davidb.github.com/yuicompressor-maven-plugin/usage_compress.html
and here is the sample pom.xml I use,
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- yuicompressor-maven-plugin -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>compress</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<linebreakpos>-1</linebreakpos>
<encoding>UTF-8</encoding>
<nosuffix>true</nosuffix>
<force>true</force>
<jswarn>false</jswarn>
<webappDirectory>${project.build.directory}/minified</webappDirectory>
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
<output>${project.build.directory}/${project.build.finalName}/js/abc-min.js</output>
<includes>
<include>${basedir}/src/main/webapp/js/comments.txt</include>
<include>${project.build.directory}/minified/js/def.js</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceExcludes>js/**/*.js,js/**/*.txt,css/**/*.css,css/**/*.txt</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I have read similar posts but could not figure out why it's not bounded to "process-resources". Phase and Goal are explicitly set so not sure why it's not called. Is there a way to debug why yuicompressor-maven-plugin is not called during "mvn package"? I use maven 2.2.1. Perhaps the version of my Maven won't work with the plugin?
thanks for your help,
syamashi

You simply need to put the running out of the pluginManagement area into the usual plugins area like:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
....
</plugin>
</plugins>
</build>
In pluginManagement you define only the default for plugin in particular the verison but you really don't bound to real execution. For other plugins etc. this works cause the are alreay defined in the build area of the supoer pom so this give you the opportunity to redefine them via pluginManagement but not with a plugin which never has been part of any build area.

Related

Where do I specify my custom reverse engineering class when using the hibernate-tools plugin for maven?

I have a custom strategy but I can't figure out how to get this plugin to use it.
My relevent pom section is:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
</plugin>
<plugin>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools-maven-plugin</artifactId>
<version>5.4.1.Final</version>
<executions>
<execution>
<id>Display Help</id>
<phase>validate</phase>
<goals>
<goal>help</goal>
</goals>
</execution>
<execution>
<id>Entity generation</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<templatePath>src/main/resources/templates/</templatePath>
<!-- Defaults: -->
<outputDirectory>generated-sources/</outputDirectory>
<ejb3>false</ejb3>
<jdk5>false</jdk5>
</configuration>
</execution>
<execution>
<id>Schema generation</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<!--Possible targetType: SCRIPT (default), STDOUT, DATABASE -->
<targetTypes>
<param>SCRIPT</param>
<param>STDOUT</param>
<param>DATABASE</param>
</targetTypes>
<!-- Defaults: -->
<outputDirectory>generated-resources/</outputDirectory>
<!--Possible schemaExportAction: CREATE (default), DROP, BOTH -->
<schemaExportAction>CREATE</schemaExportAction>
<outputFileName>schema.ddl</outputFileName>
<delimiter>;</delimiter>
<haltOnError>true</haltOnError>
<format>true</format>
</configuration>
</execution>
</executions>
<configuration>
<revengFile>src/main/hibernate/hibernate.reveng.xml</revengFile>
<!-- Defaults: -->
<packageName></packageName>
<configFile>src/main/hibernate/hibernate.cfg.xml</configFile>
<detectManyToMany>true</detectManyToMany>
<detectOneToOne>true</detectOneToOne>
<detectOptimisticLock>true</detectOptimisticLock>
<createCollectionForForeignKey>true</createCollectionForForeignKey>
<createManyToOneForForeignKey>true</createManyToOneForForeignKey>
</configuration>
<dependencies>
<!-- databases -->
<dependency>
<!-- DB Driver of your choice -->
<groupId>com.oracle</groupId>
<artifactId>oracle-jdbc8</artifactId>
<version>18</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>5.4.1.Final</version>
</plugin>
<!--
<plugin>
<groupId>org.springframework.boot</groupId>
</plugin>
-->
</plugins>
</pluginManagement>
</build>
And my hibernate.reveng.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="DATE" hibernate-type="java.time.LocalDate"/>
<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.time.LocalDateTime"/>
</type-mapping>
</hibernate-reverse-engineering>
Additionally, although in the config I have specified to use "src/main/hibernate/hibernate.cfg.xml" it is reading "hibernate.properties"
I guess the example I got https://github.com/stadler/hibernate-tools-maven-plugin has the wrong configuration property name.
So:
1) The initial question
2) How do I configure this to use the specified configuration file?
3) Where is there a list of all the configuration problems and finally despite having
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>5.4.1.Final</version>
</plugin>
</plugins>
</pluginManagement>
I am getting "plugin execution not covered by lifecycle" in eclipse
So apparently I did not correctly follow this StackOverflow answer How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
The documentation says add a revengStrategy configuration to the plugin with the full name of the class that extends DefaultReverseEngineeringStrategy. However when you try this, it throws class not instanced error. I have raised an issue with hibernate tools.
However, I have seen solutions where this is working if you have multi module project. The custom class should be part of a different module and that module should be added as a plugin dependency.
If I hear back from hibernate tools, you can find it here later
https://jonamlabs.com/how-to-use-hibernate-tools-maven-plugin-to-generate-jpa-entities-from-an-existing-database/

Filter maven resources with filter-file from external dependency

Given a property file in maven project A
I want to use them in project B for resource filtering.
So in Project B I use
<build>
<filters>
<filter>${project.build.directory}/myFile.properties</filter>
</filters>
</build>
To filter my resources based on values in myFile.properties This file is stored in project A. So I include it with
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>groupa</groupId>
<artifactId>a</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Problem is that the resource filtering happens before the dependency is copied. So filtering does work when copying myFile.properties manually to ${project.build.directory} but it does not work with a mvn clean ...
How can I copy the filterFile before the actual filtering happens?
Maven plugins are executed in the order they appear in the pom. AFAIK the plugins configured in the parent (and the super pom) are executed before the plugins of the pom.
My suggestion is declaring the resources plugin explicitely after the dependency plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- ... -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!-- ... -->
</plugin>
</plugins>
</build>

Not able to generate client code with wsdl2java and maven using CXF

I'm using maven cxf-codegen-plugin to generate client files from wsdl but not able to do so.
I want that all the wsdl files in the folder src/main/wsdl should be scanned and corresponding clients should be generated in separate folders. Please help.
My pom.xml is :
<build>
<finalName>someFileName</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>process-resources</phase>
<configuration>
<sourceRoot>src/main/java</sourceRoot>
<wsdlRoot>${basedir}/src/main/wsdl</wsdlRoot>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
here's how I'm doing it with version 2.7.4, and having the generated code created in different packages :
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/MyWsdl1.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>urn:mycompany:myproduct1:v1_0=com.my.project.product1</extraarg>
<extraarg>-p</extraarg>
<extraarg>http://www.w3.org/2001/XMLSchema=com.my.project.common</extraarg>
</extraargs>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/MyWsdl2.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>urn:mycompany:myproduct2:v1_0=com.my.project.product2</extraarg>
<extraarg>-p</extraarg>
<extraarg>http://www.w3.org/2001/XMLSchema=com.my.project.common</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Here's where you can find out more about the extra-args :
http://cxf.apache.org/docs/wsdl-to-java.html
For an automatic scan of the wsdl folder, this works good too :
<configuration>
<sourceRoot>${project.build.directory}/generated/src/main/java</sourceRoot>
<wsdlRoot>${basedir}/src/main/wsdl</wsdlRoot>
<includes>
<include>**/*.wsdl</include>
</includes>
</configuration>
Hope it helps!
I realize this is an old question, but I just ran into this, so I wanted to reply for the benefit of others. You are right on commenting out the <pluginManagement> tag see here. However for the error in Eclipse that says:
Plugin execution not covered by lifecycle configuration
You will need to install the m2e connector for build-helper-maven-plugin (click on the error, and Eclipse should guide you to install it)
I put plugins tag inside pluginManagement tag and error disappeared:
<pluginManagement>
<plugins>
<plugin>
..........................
</plugin>
</plugins>
</pluginManagement>

How do I build only one JAR file with classifier?

I'm using Maven 2 and maven-jar-plugin to build my jar.
I'd like to generate only a jar with a classifier. Is it possible?
In my example I'd like to generate only the myjar-another-1.0.jar but not myjar-1.0.jar.
After take a look at this question I tried to skip the default-jar. But this seems to work only with version 3 of Maven (haven't tried thou.
The parent is to do the
<modules>
Thanks all!
Here is the relevant piece of my pom.xml:
Also tried in the global configuration segment.
<project>
<!-- Definition of the Parent (only an aggregator) -->
<build>
<plugins>
<!-- <artifactId>maven-bundle-plugin</artifactId> -->
<!-- surefire -->
<!-- <artifactId>maven-source-plugin</artifactId> -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<classifier>another</classifier>
</configuration>
<executions>
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Just use it for the plugin element:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<classifier>another</classifier>
</configuration>
</plugin>
</plugins>

Maven Release Plugin deployment of sources.jar and javadoc.jar

I use maven release plugin for generating release of my project. I do not want to generate Javadoc all time I build. On the other hand when I call release:perform I would like if maven would generate sources.jar and javadoc.jar and would deploy it to maven release repository. Just because I am curious how deploying source.jar can be disabled, since It looks like it is deployed by default.
From the documentation of Maven Release Plugin, there is a useReleaseProfile parameter, which determines Whether to use the release profile that adds sources and javadocs to the released artifact, if appropriate. This is true by default. You can try changing this as appropriate to enable/disable source/javadocs.
Use the releaseProfiles parameter (example: src,javadoc) to turn on one or more profiles, and in these profiles, define the source and javadoc generation:
<profiles>
<profile>
<id>src</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>javadoc</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>