maven - generate sources is not working - maven

please advise if possible on this
I am running mvn package source:jar and get a module.jar and module-sources.jar as expected in the target directory
However, I have 2 issues:
1) I when I do : mvn install source:jar I get a -source.jar in my "target" in
the local projects folder, HOWEVER, NOT in the "local-repository (under .m2
on my PC). Even though, I do get a module.jar with binaries installed.
EDIT: I have figured this item (1): It works if I place "source:jar" before "install". That is mvn source:jar install instead of mvn install source:jar
2) I want to NOT HAVE TO run source:jar in the command line to generate the sources. Because, when I use GO continuous integration tool, that I have no control over, they do not have a maven goal mvn source:jar there.
I know that with the configurations in the pom.xml it can be achieved, and I did see it occuring once or twice, but it stopped working (well, obviously I made a change,that I do not know that broke this)
My pom.xml has the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${source.directory}</outputDirectory>
<finalName>${project.jar.name}</finalName>
<fileNameMapping>no-version</fileNameMapping>
<classifier>${source.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
So, ultimately, when I run either mvn package or mvn install or I want to have sources generated as a jar file next to the regular project.jar (or in the specified folder, but it is not essential)

Related

Pomless Tycho build + maven release plugin

I have a pomless tycho build which I want to release with the maven release plugin. The issue I have is that I get errors from the git plugins for the generated .polyglot.build.properties even though it is not included in the configuration of the git-add goal.
Parent pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<localCheckout>true</localCheckout>
<preparationGoals>
org.eclipse.tycho:tycho-versions-plugin:${tycho.version}:update-eclipse-metadata
build-helper:parse-version
org.apache.maven.plugins:maven-scm-plugin:1.9.5:add
org.apache.maven.plugins:maven-scm-plugin:1.9.5:checkin
</preparationGoals>
<completionGoals>
org.eclipse.tycho:tycho-versions-plugin:${tycho.version}:update-eclipse-metadata
build-helper:parse-version
org.apache.maven.plugins:maven-scm-plugin:1.9.5:add
org.apache.maven.plugins:maven-scm-plugin:1.9.5:checkin
</completionGoals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.5</version>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>add</goal>
<goal>checkin</goal>
</goals>
<configuration>
<includes>**/META-INF/MANIFEST.MF,**/feature.xml,**/*.product,**/category.xml,release.properties</includes>
<excludes>**/target/**</excludes>
<message>Changing the version to reflect the pom versions for the release</message>
<pushChanges>false</pushChanges>
</configuration>
</execution>
</executions>
</plugin>
The error I get:
fatal: pathspec 'my.plugin/.polyglot.build.properties'
did not match any files
After looking at the source code of tycho-pomless, polyglot, and maven-release, I conclude pomless build can't work with maven release. I need to add pom.xml
The reason is:
tycho-pomless uses polyglot, which creates an temporary pom from the build.properties, which is deleted when the JVM exits
maven release:prepare spawns a child maven process to execute the preparation goals. When the child process finishes, this deletes the temporary files. The available mavenExecutorId values are "invoker" which invokes a new process, and "forked", which forks the process. Which means both spawn a new JVM.
So in conclusion, it looks like tycho-pomless (or any polyglot build, really) and maven-release are incompatible in the presence of preparation goals, and there seems to be no workaround. The possible workaround of executin the preparation goals in the same JVM seems to be unavailable. So the solution is adding a pom.xml
Check first is this is similar to this question, where the plugin does finds the files it should add, but, when creating the command line, it does not respect the correct root directory.
See if the path mentioned in pathspec 'my.plugin/.polyglot.build.properties' the correct one.
Double-check if your POM and folder hierarchy is at the right place, meaning in the project root folder.
The OP kutschkem refers in the comments to:
the .polyglot.build.properties is a temporary file, deleted by the release:prepare child process exit.
But release plugin picks it up as the pom of the project to checkin.
That might be why I see in Tycho/Reproducible Version Qualifiers
<jgit.ignore>
pom.xml
.polyglot.build.properties
</jgit.ignore>

Using maven-deploy-plugin to deploy Eclipse product

I am trying to deploy an Eclipse product to Nexus repository. I am somewhat successful, but still get some errors that I am not sure how to handle.
I am using maven-deploy-plugin in the feature (F) that builds product:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>snapshots</repositoryId>
<packaging>zip</packaging>
<generatePom>true</generatePom>
<url>http://repo:8081/nexus/content/repositories/snapshots</url>
<groupId>my.group</groupId>
<artifactId>my.artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<file>
target/products/product.zip
</file>
</configuration>
</execution>
</executions>
</plugin>
I execute 'mvn clean install' to build the product and then 'mvn deploy' on F. If I do that then I get error
Exception while publishing product /home/akravets/dev/workspaces/trunk/my.repository.feature/myProduct.product: publishing result: [Included element my.product.feature.feature.group 8.0.1.R20180301-1431 is missing. Cannot determine filter for requirement to this element.] -> [Help 1]
I've read discussions about this issue, but nothing seems relevant to my issue because I don't have any defined deploy phases besides the one in maven-deploy-plugin.
If I change phase of maven-deploy-plugin to 'install' I get almost satisfactory results. The zip file and generated pom get deployed to repository, but the build fails with error
product.qualifier-p2artifacts.xml. Return code is: 400, ReasonPhrase: Bad Request.
Why does this file even gets considered to be deployed to repository when it's not in file element of maven-deploy-plugin and it's not in the directory structure where zip file is: target/ vs target/product/product.zip? Is this because maven-deploy-plugin is executed during the install phase and it picks up all generated resources as candidates for deployment?
I simply recommend you to use Maven-Tycho to deploy Eclipse RCP product.Tycho determines the dependencies of a plug-in via the MANIFEST.MF file of the plug-in and fetches the required plugins-bundles through the online repositories.
You can check this git repository as an example; rcp - tycho

Eclipse Maven multi module project with xmlbeans

I have a multi module project, in which one of the module ( say MODULE-A) generates sources and classes using xmlbeans plugin. So everytime when I do a clean install of parent project, eclipse recognizes all of the generated sources as new classes, and I don't want to commit the same files again and again when there is no schema change. To overcome this problem, I wrapped xmlbeans build under a profile so that I can build it with profile whenever there is a schema change. But it didn't solve the problem completely.
Whenever I try to do clean build of parent, MODULE-A is not creating 'schemaorg_apache_xmlbeans' under build directory ( which is something only generated by xmlbean plugin when I run with profile ). I can tell maven to exclude 'schemaorg_apache_xmlbeans' from the clean task. But I want to know if this is the right way to handle.
Appreciate your responses.
Thanks in advance
One alternative to this approach is to add this plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
This will allow the generated-sources to be added as a source folder so every time it generates you will have them built and available. You wouldn't commit these but when the actual jar gets built/released they will be in there and work all the same. This allows you to always be using code most up to date with your schema. This may not be the best solution for you but I found it to be a good idea when I ran into a similar situation.

Maven Multiple platform dependent Packages

I have written an application in Java that can be used on both Linux and Windows. Currently by running mvn package, my maven build system will generate a .msi using WiX.
Is there a way of creating two package 'tasks' so I can say either mvn package-windows ormvn package-linux`
If you want to package both versions (Linux and Windows), you can bind your mvn package phase to an extra phase that would build another artifact.
...
<plugin>
<groupId>org.group.extra</groupId>
<artifactId>extra-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
[...]
</configuration>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
...
It was probably what you have already done with maven-wix-plugin.
You can use either use profile to do that or a better thing would be to have three project.
One for the core and then one for Linux and one for Windows that uses the core project.

Best way to auto compile compass-style SASS via maven

referring to SASS implementation for Java? :
What is the best way to auto-compile compass-style.org stylesheets in maven goal compile respectively package?
I would not like to ship too many self-compiled libraries nor do I want to dynamically ship compiled files via filters like https://code.google.com/p/sass-java ( https://github.com/darrinholst/sass-java )
Any alternatives than hooking up shellscripts / ant scripts which requires installed ruby and compass on the client?
What is the detailed difference between SASS and Compass Stylesheets, any problems with "sass-tools" when regularly using "compass"? => Which mvn plugins are "compass aware"?!
I suppose you know about this Maven plugin (mentioned in SASS implementation for Java?)? : https://github.com/Jasig/sass-maven-plugin
(I haven't tried it myself yet.)
UPDATE: that plugin is no longer supported. However, this fork seems to be healthy at present, so it might be an option for some: https://github.com/GeoDienstenCentrum/sass-maven-plugin
I found this, it's not a special compass/sass plugin but it works
https://gist.github.com/1671207
I was using the Sass Maven Plugin by nl.geodienstencentrum.maven but it uses Ruby and is very slow.
I've now switched to:
Libsass Maven Plugin
https://github.com/warmuuh/libsass-maven-plugin
This uses C and our compile times are much less (8.6 seconds to -> 2 seconds)
I tried several ways to compile my app (java, Wicket, using Zurb Foundation Sites, node-sass with depebndency of lib-sass). To tell you the truth, all the maven plugins were somewhere a deadend, especially when my scss contained the !global flag. (This flag came with foundations.)
So the final solution for us was to build with npm first then use maven.
Npm builds into src/main/webapp/"myDir" dir. I excluded this dir in git.
The jason file has a line like:
"scripts": {
....
"build-css": "node node_modules/node-sass/bin/node-sass --include-path myScssDir myScssDir/myScss.scss --output src/main/webapp/myDir/css",
....
}
Then build with maven and it will move the builded css ino my war.
For some help (create the nonexisting "myDir" dir) i used mkdirp.
In my jason there is:
"scripts": {
"create-dirs": "mkdirp src/main/webapp/myDir/",
....
}
So i run "npm i" to install all my dependencies locally into node-modules dir. This is gitignored.
Then i run "npm run create-dirs" to create the necessary myDir. This is gitignored as well.
Then i run "npm run build-css" to compile my css-s and js-s into myDir.
Finally i make a maven build.
With a hudson/jenkins build, you can easily do these in one job.
One improvement i can think of is to run npm via ant during maven build. I'll get back to you when i have a proof of concept of this.
//One extra hint: if you are developing under corporate environment and Windows7 you may have to add permissions to symbolic links for npm build. If you find errors in npm build, it worth a try: https://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7
Since libsass-is-deprecated, and the fork bases on the same "archived lib": https://github.com/bit3/jsass ..bases on libsass...
How do I migrate? ... Someone might find this useful:
[choco|brew|npm] install sass
Source: https://sass-lang.com/install
(I would not do it in ci, but we could!)
With the "good ole" exec-maven-plugin, adopted from Spring Petclinic (site|repo) (previously extracting webjars-bootstrap, originally they used that same libsass-maven-plugin):
<profile>
<id>css</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<!-- process-resources > genererate-resources (i.e. later)-->
<phase>process-resources</phase>
</execution>
</executions>
<configuration>
<!-- must be in $PATH !! -->
<executable>sass</executable>
<!-- it is quite silent, when everything works well -->
<useMavenLogger>true</useMavenLogger>
<arguments>
<!-- additional sass path(s), adjust to our suits -->
<argument>--load-path=${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/</argument>
<argument>--no-source-map</argument>
<argument>--verbose</argument>
<argument>--trace</argument>
<!-- for more args, see https://stackoverflow.com/a/70228043/592355 // `sass` -->
<argument>${basedir}/src/main/scss/my.scss</argument>
<argument>/path/to/my/dest/my.css</argument>
</arguments>
<!-- more config, when we like ... -->
</configuration>
</plugin>
<!-- this is not part of the answer, but unpacks us required scss: -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<!-- genererate-resources < process-resources (i.e. prior)-->
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.webjars.npm</groupId>
<artifactId>bootstrap</artifactId>
<version>${webjars-bootstrap.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/webjars</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Finally:
mvn process-resources -Pcss
(assuming no tests, no clean, no compile, "it is quite silent, when everything works well")

Resources