Unable to see generated test source folder with mojo's build-helper - java

I have added the mojo's plugin build-helper to my project pom to generate a new test source folder for my integration tests. When I run the phase, generate-test-sources
mvn generate-test-sources
I could see the below console output showing the test source folder has generated, but When I look in project explorer, I don't see any folder which was created.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for *******
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.google.guava:guava:jar -> version 18.0 vs ${guava.version} # line 154, column 21
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.unitils:unitils-core:jar -> duplicate declaration of version 3.3 # line 164, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building projectxxStaticAnalysisxxxxx versionxxxxx
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # StaticAnalysis ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # StaticAnalysis ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- build-helper-maven-plugin:1.9:add-test-source (add-integration-test-sources) # StaticAnalysis ---
[INFO] Test Source directory: C:\{workspacepath}\src\integration-test\java added.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.421 s
[INFO] Finished at: 2014-11-25T11:26:59-06:00
[INFO] Final Memory: 9M/303M
[INFO] ------------------------------------------------------------------------
Below is my pom plugin configuration
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Am I doing something wrong?. Please help.
Thanks

I think I found the answer to my question. I was actually expecting build-helper plugin to create the test folder for me. But the fact is, it won't create the folder for you.
You have to create the test folder and use this build-helper plugin to tell maven to treat the folder you created as test folder as shown in my pom above. I was able fix my issue by creating a new test folder and ran the following command
mvn generate-test-sources eclipse:eclipse
Hope this helps someone!

Related

Convenient way to update version of multi-module project in Eclipse

I have a Maven multi-module project in Eclipse.
Each time I want to update the version, I go to Run As -> Run Configurations..., change the parameter newVersion of the goal versions:set to a higher number and then run the goal.
Is there something more direct?
Note that I cannot use the CI-friendly versions because they clash with the Maven release plugin.
Following the idea of https://stackoverflow.com/a/34091470/927493,
I configured the newVersion parameter to be ${string_prompt:newVersion} as shown in the image below
Then I get prompted for the version number which works fine.
Based on the answer from JF Meijer, here's a Launch Configuration explanation for M2E, which I suspect you already have installed, which does exactly what you're asking.
Launch Create Dialog
Open "Run Configurations..."
Select "Maven Build"
Click "New Launch Configuration" (in the top left)
Give it a name (Like "Set Version")
Click "Workspace..." And select the parent pom project
Enter "versions:set" under Goals
scroll down (can be hidden)
Under "Parameters" select Add... on the right
Add a Parameter with
Name = newVersion
Value = ${string_prompt:"New Version":0.0.1-SNAPSHOT}
so, to expand on what JP Meijer already pointed out, the variable string_prompt, as shown under step 9, supports a distinct name, like "New Version", and a default value, in this case 0.0.1-SNAPSHOT.
Now, Apply, Save, and Run!
Here is a script that checks if the maven build system needs updates. By running this script, you will get all the updates (but none of them will be applied). This lets you change all, some or none, as you see fit.
mvn versions:display-plugin-updates
mvn versions:display-parent-updates
mvn versions:display-dependency-updates
I typically save this script in a top-level check-versions.sh or check-versions.cmd (adjusting for the scripting language).
For this script to work, in /project/build/plugins you'll need the org.codehaus.mojo:versions-maven-plugin:2.7 or greater. I typically configure the plugin like so
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
As this doesn't make backup pom.xml files which pollute my git history.
The first few times you run this, you might notice that the inherited plugins show themselves to be out of date (as they are effectively built-in to the defaults in the maven default parent pom.xml). You will have to explicitly define the defaults to a newer release to get them to stop reporting.
In addition, you will find that a lot of the plugins will still report because it isn't clear what is the minimum required version of Java and the minimum required version of Apache Maven. To encode these requirements into the pom.xml, you will use the Maven Enforcer plugin. An example of mine that forces Maven version 3.5.4 and Java version 11 is
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.5.4</version>
</requireMavenVersion>
<requireJavaVersion>
<version>11</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
With these tools in place, I currently get the output on one of my projects
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.edwbuck.parserhelp:pascal-adapter >----------------
[INFO] Building pascal-adapter 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:display-plugin-updates (default-cli) # pascal-adapter ---
[INFO] artifact com.github.sevntu-checkstyle:dsm-maven-plugin: checking for updates from central
[INFO] artifact net.nicoulaj.maven.plugins:checksum-maven-plugin: checking for updates from central
[INFO]
[INFO] The following plugin updates are available:
[INFO] maven-project-info-reports-plugin .................... 2.6 -> 3.0.0
[INFO]
[INFO] All plugins have a version specified.
[INFO]
[INFO] Project inherits minimum Maven version as: 3.5.4
[INFO] Plugins require minimum Maven version of: 3.2.1
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.976 s
[INFO] Finished at: 2020-04-16T07:52:12-05:00
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.edwbuck.parserhelp:pascal-adapter >----------------
[INFO] Building pascal-adapter 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:display-parent-updates (default-cli) # pascal-adapter ---
[INFO] Project does not have a parent.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.325 s
[INFO] Finished at: 2020-04-16T07:52:15-05:00
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.edwbuck.parserhelp:pascal-adapter >----------------
[INFO] Building pascal-adapter 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:display-dependency-updates (default-cli) # pascal-adapter ---
[INFO] artifact com.edwbuck.parserhelp:pascal_client: checking for updates from central
[INFO] artifact org.junit.jupiter:junit-jupiter-engine: checking for updates from central
[INFO] artifact org.junit.jupiter:junit-jupiter-api: checking for updates from central
[INFO] artifact org.influxdb:influxdb-java: checking for updates from central
[INFO] The following dependencies in Dependencies have newer versions:
[INFO] org.junit.jupiter:junit-jupiter-api ................... 5.6.0 -> 5.6.2
[INFO] org.junit.jupiter:junit-jupiter-engine ................ 5.6.0 -> 5.6.2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.848 s
[INFO] Finished at: 2020-04-16T07:52:18-05:00
[INFO] ------------------------------------------------------------------------
which indicates I need to update my maven-project-info-reports-plugin and my org.junit.jupiter:junit-jupiter-api and org.junit.jupiter:junit-jupiter-engine plugins.
Normally I don't use the maven versions plugin to actually do the update in the pom.xml file, because text editors are fast, if you're doing all the updates you want to do in the pom.xml at one time.
Currently the maven versions plugin offered by codehaus doesn't have an command line option to automatically update more than one version at a time. The reasons it is not there is simple. To use the versions:update-properties plugin, one needs to either:
Define the update policy (what to update / what not to update) in the pom.xml.
Define the update policy (what to update / what not to update) on the command line.
These policies are verbose as they cover the entire project. Yes, they can use glob matching, but they're still verbose. For my personal projects, I notice that for them to give me proper handling, I update them too often, so I leave them out of the picture, instead deciding what to update or not update at the time I work on the output of my check-updates script.
That's because it is not always safe to automatically update plugins and dependencies. Sometimes the next version of a plugin requires code changes to the project. For example, projects shifting from Java 8 to Java 9 require alterations to how they are built and linked. The same goes for dependencies, if you want to keep the code bound to non-deprecated APIs.

Getting The POM for org.testng:testng:jar:5.14.3 is invalid and java.lang.NoClassDefFoundError while running pom.xml

Getting java.lang.NoClassDefFoundError while running pom.xml, I have updated maven surefire plugin in maven dependency as well as updated maven version but still getting the error,
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building eGem 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.testng:testng:jar:5.14.3 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.testng:testng:jar:5.14.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.testng:testng:jar:5.14.5 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for com.beust:jcommander:jar:1.66 is missing, no dependency information available
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # eGem ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 13 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # eGem ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # eGem ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 12 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) # eGem ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # eGem ---
[WARNING] Error injecting: org.apache.maven.plugin.surefire.SurefirePlugin
java.lang.NoClassDefFoundError: org/apache/maven/surefire/util/NestedCheckedException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
Try adding the configuration section and see if it works, or run maven in debug mode for further debugging.
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
Debugging Classpath Problems
Here's some general tips to try:
Run Maven with --debug (or equivalently, -X) to get more detailed
output Check your forkCount. If forkCount=0 (or forkMode=never, the
deprecated version of that), it's impossible to use the system class
loader or a plain old Java classpath; we have to use an isolated
class loader.
If you're using the defaults, useSystemClassLoader=true and
useManifestOnlyJar=false. In that case, look at the generated
manifest-only Surefire booter JAR. Open it up (it's just a zip) and
read its manifest.
Run Maven with -Dmaven.surefire.debug, and attach to the running
process with a debugger.

Maven not failing on compiler warnings

I have a maven project, and as I move to production I want the build to fail on any compiler warnings.
I have looked through the web and configured my pom.xml with guidance from this SO post
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-Werror</compilerArgument>
<compilerArgument>-Xlint</compilerArgument>
<fork>true</fork>
</configuration>
</plugin>
In my project, I removed some parameterization to create an unchecked cast:
return ((Map<String, Object>)getProperty("settings", Map.class).get("aSetting");
Which is correctly identified by both eclipse and maven as a compiler warning. However, despite the warning showing up in maven's compile log, the project still compiles and returns success:
sysadmin#ubunyu:~/workspace/project$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My Project 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) # project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.4:compile (default-compile) # project ---
[INFO] Compiling 13 source files to /home/sysadmin/workspace/project/target/classes
[WARNING] /home/sysadmin/workspace/project/src/main/java/project/package/MyClass.java:[305,69] [unchecked] unchecked cast
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.753s
[INFO] Finished at: Fri Jul 24 11:50:03 EDT 2015
[INFO] Final Memory: 8M/161M
[INFO] ------------------------------------------------------------------------
----------------
I've tried different combinations of -Werror, -Xlint, fork, showWarning, and showDepreciation in the compiler configuration, but nothing is producing an compilation error as I'd expect.
Use
<compilerArguments>
<Xlint/>
<Xlint>cast</Xlint>
</compilerArguments>

YUI Compressor Maven plugin executed at wrong time and tomcat plugin not using yui-compressor output

I am trying to use the YUI Compressor plugin for maven to compress my CSS and JavaScript, but I'm experiencing two problems.
My configuration properly compresses and aggregates the JavaScript files, but if I run mvn package to make a war file, maven will compress the JavaScript files BEFORE it copies over the src/main/webapp folder. This overwrites all of the compressed css and JavaScript files. How can I fix this?
How do I get the tomcat maven plugin to use the compressed JavaScript files rather than the ones in my src/main/webapp/scripts folder? When my application is trying to read all.js, it is failing because it is located in the target/ directory and not in my src/main/webapps folder.
<!-- Tomcat -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<warFile>target/myapp-1.0.war</warFile>
</configuration>
</plugin>
<!-- YUI Compressor -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/jwplayer.js</exclude>
<exclude>**/audio-player-noswfobject.js</exclude>
<exclude>**/audio-player-uncompressed.js</exclude>
<exclude>**/audio-player.js</exclude>
<exclude>**/jscharts.js</exclude>
<exclude>**/jquery-ui-1.8.16.custom.min.js</exclude>
</excludes>
<nosuffix>true</nosuffix>
<jswarn>false</jswarn>
<force>false</force>
<aggregations>
<aggregation>
<removeIncluded>false</removeIncluded>
<insertNewLine>true</insertNewLine>
<output>${project.build.directory}/${project.build.finalName}/scripts/all.js</output>
<includes>
<include>**/json/json2.js</include>
<include>**/jwplayer/jwplayer.js</include>
<include>**/font/font.js</include>
<include>**/underscore/underscore.js</include>
<include>**/jquery/jquery-1.7.1.js</include>
<include>**/jquery/jquery-ui-1.8.16.custom.min.js</include>
<include>**/jquery/jquery.cookie.js</include>
<include>**/jquery/jquery.fancybox.js</include>
<include>**/jquery/jquery.highlight.js</include>
<include>**/jquery/jquery.jcrop.js</include>
<include>**/jquery/jquery.tmpl.js</include>
<include>**/jquery/farbtastic.js</include>
<include>**/jscharts/jscharts.js</include>
<include>**/myapp/homepage.js</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
Or am I just going about my goal the wrong way?
Here is the maven output when packaging the war. You can see that even if I tell the yui:compress goal to in the pre-package phase, it still occurs before the copying of the resources since this occurs in the package phase:
[INFO] ------------------------------------------------------------------------
[INFO] Building My App 1.0
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
Downloading: http://snapshots.repository.codehaus.org/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
Downloading: http://download.java.net/maven/2/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
Downloading: http://oss.sonatype.org/content/groups/public/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
Downloaded: http://oss.sonatype.org/content/groups/public/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml (442 B at 2.1 KB/sec)
Downloaded: http://repo1.maven.org/maven2/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml (403 B at 0.9 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # myapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 26 resources
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # myapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default) # myapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- aspectj-maven-plugin:1.3:compile (default) # myapp ---
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # myapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # myapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- aspectj-maven-plugin:1.3:test-compile (default) # myapp ---
[INFO] No modifications found skipping aspectJ compile
[INFO]
[INFO] --- maven-surefire-plugin:2.6:test (default-test) # myapp ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- yuicompressor-maven-plugin:1.2:compress (default) # myapp ---
[INFO] 960.css (9989b) -> 960.css (5897b)[59%]
[INFO] base.css (24210b) -> base.css (16437b)[67%]
[INFO] reset.css (2062b) -> reset.css (1096b)[53%]
[INFO] text.css (1270b) -> text.css (598b)[47%]
[INFO] tinymce.css (1994b) -> tinymce.css (1277b)[64%]
[INFO] jquery.fancybox-1.3.4.css (8852b) -> jquery.fancybox-1.3.4.css (6975b)[78%]
[INFO] farbtastic.css (1362b) -> farbtastic.css (478b)[35%]
[INFO] jquery.jcrop.css (748b) -> jquery.jcrop.css (582b)[77%]
[INFO] base.css (34567b) -> base.css (25034b)[72%]
[INFO] jquery-ui-1.8.11.custom.css (33994b) -> jquery-ui-1.8.11.custom.css (25351b)[74%]
.... (tons of javascript files)
[INFO] why.js (515b) -> why.js (354b)[68%]
[INFO] underscore.js (26960b) -> underscore.js (9472b)[35%]
[INFO] total input (1832512b) -> output (1198425b)[65%]
[INFO] generate aggregation : C:\Users\egervari\IdeaProjects\myapp-development\target\myapp-1.0\scripts\all.js
[INFO] all.js (564342b)
[INFO] nb warnings: 0, nb errors: 0
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) # myapp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [myapp] in [C:\Users\egervari\IdeaProjects\myapp-development\target\myapp-1.0]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\egervari\IdeaProjects\myapp-development\src\main\webapp]
Even if changing the phase did work, then I would also have to get this compression to run before tomcat:run as well.
Is maven just the wrong tool for the job you think? Or is maven/java just not up-to-snuff with heavy javascript development? Why is this so hard?
I faced a similar issue and I changed my phase to package. Hopefully this will help someone else as well.
This is tricky. This has to do with the nosuffix config option. If you remove the nosuffix option, the minification works as expected.
If you really have to have nosuffix then you need to change the execution phase to "package".
<executions>
<execution>
<phase>package</phase>
<goals>
......
.....
Any phase before prepare-resources doesn't work because when the war is built, it picks up the js from the original source location and thereby overwrites the minified js (created during prepare-resources phase) in the target directory.
Minification works when you remove nosuffix because during package phase, the file names are different, so there is no over-writing of the files and you will see both the minified and non-minified js files in your target directory.
To work around this issue you can somethin like.
(1) Put your personal coded javascript in src/main/js not in src/main/webapp. Use the mvn convention for JS placement.
*Note: for libraries that you include, e.g. jQuery or whatever else, you can just dump them in src/main/webapp, that is fine. Those will already have minimized javascript that you will never be modifying.
(2) Tune your YUI plugin to (a) ignore javascript you did not code, (b) to compile the compressed javascript to an output folder.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<excludes>
<exclude>**/ui-framework/**</exclude>
</excludes>
<outputDirectory>${yui.outputdir}</outputDirectory>
</configuration>
</plugin>
So with this, we can make the following exercise.
mvn process-resources
└── target
├── classes
│   ├── default.logback.xml
│   └── props
│   ├── default.props
│   └── production.default.props
├── packageLinkDefs.properties
└── yui-compressed
└── jasmineDummyExample_element_mover.js
The point here is that YUI is compiling the compressed javascript to its own output folder and the war plugin has no idea about it.
(3) Finally you just need to tune your war plugin to copy the yui compiled sources.
As long as you are following the javascript convention for maven, where your javascript should have been coded under src/main/js/, your war plugin by default will not be copying your javascipt (sounds strange right?).
By default, your war plugin will be copying whatever static resources are under src/main/webapp.
This is convenient, because it allows you to instruct the war plugin to keep its default behavior of copying the src/main/webapp to the final war file and, in addition, to copy your /src/target/yui-compressed folder. In this manner, there are not overlapping files in both folders, there is not file overwriting in the output directory.
This is illustrated in the following snippet:
$ mvn war:war
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building lift-someproject Project 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-war-plugin:2.5:war (default-cli) # lift-someproject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [lift-someproject] in [D:\scalaWorkspace\liftsomeprojectTwo\lift-someproject\target\lift-someproject]
[INFO] Processing war project
[INFO] Copying webapp webResources [D:\scalaWorkspace\liftsomeprojectTwo\lift-someproject\target\yui-compressed] to [D:\scalaWorkspace\liftsomeprojectTwo\lift-someproject\target\lift-someproject]
[INFO] Copying webapp resources [D:\scalaWorkspace\liftsomeprojectTwo\lift-someproject\src\main\webapp]
[INFO] Webapp assembled in [820 msecs]
[INFO] Building war: D:\scalaWorkspace\liftsomeprojectTwo\lift-someproject\target\lift-someproject.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.968s
[INFO] Finished at: Tue Dec 23 20:17:59 CET 2014
[INFO] Final Memory: 11M/246M
[INFO] ------------------------------------------------------------------------
You can tune your war file to be aware of the special folder with your not-crushed yui compressed JS files:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<webResources>
<resource>
<directory>${yui.outputdir}</directory>
<targetPath>js</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
If you use Jetty for rapid development, you will want some further teaking on that plugin, to make sure that it finds your hand coded javascript in src/main/js.
That should work.

Spring in Action: 3rd edition: Chapter 1...Maven and the POM file

I'm getting this error while going through Spring in Action: 3rd edition: Chapter 1. I've managed to get the source code from the website to work. My IDE is STS. Thanks
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - Knights:Knights:jar:0.0.1-SNAPSHOT
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 7 source files to E:\SpringInAction\Knights\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\SpringInAction\Knights\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to E:\SpringInAction\Knights\target\test-classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
E:\SpringInAction\Knights\src\test\java\com\springinaction\knights\BraveKnightTest.java:[3,7] static import declarations are not supported in -source 1.3
(use -source 5 or higher to enable static import declarations)
import static org.mockito.Mockito.*;
E:\SpringInAction\Knights\src\test\java\com\springinaction\knights\BraveKnightTest.java:[8,3] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#Test
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Aug 24 00:12:45 CDT 2011
[INFO] Final Memory: 12M/232M
[INFO] -----------------------------------------------------------
Add this to your pom in order to tell Maven to use Version 5 of Java, by default it uses version 1.3 (see documentation):
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Categories