Building JavaFx application using Bitbucket pipelines - maven

I am trying to build JavaFx project using bitbucket pipelines. For that I am using maven:3-jdk-8 docker image. This Docker image uses OpenJDK 8 instead of Oracle's one (due to the lincensing issue) which does not include the JavaFx part. Note that I have to use Java 8 to build my project!
Problem that I am getting is that I am not able to build the application using that docker image alone.
As proposed in an answer to the same question (https://stackoverflow.com/a/40167253/2000338):
I tried using this bitbucket-pipelines.yml to try to overcome the situation:
image: maven:3-jdk-8
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- apt-get update
- apt-get install -y openjfx
- mvn clean install # -B batch mode makes Maven less verbose
In step 2 it seems that openjfx is installed properly.
But in step 3 I am getting following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project ***********: Compilation failure: Compilation failure:
[ERROR] /opt/atlassian/pipelines/agent/build/src/main/java/********/******/****/MainFx.java:[7,26] package javafx.application does not exist
It seams that it is still complaining on the JavaFx libraries missing, but I am not aware of why.
On my developer machine (Windows 7, jdk1.8.0_221) I can execute maven build without an issue.

What was missing in previous approach is that the javafx library was not on the classpath. Basically in order to make maven build work I had to add the jfxrt.jar to the classpath.
I found that in the maven:3-jdk-8 image after installing javafx the library can be found in:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
Adding this file to a classpath during build run will do the trick.
One idea (that worked for me) is to include this library in application pom/dependecy part as a system scope.
In my case I made a maven profile for that:
<profiles>
<profile>
<id>docker_build</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javaFX</artifactId>
<version>2.2</version>
<scope>system</scope>
<systemPath>${javafx-location}</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
In order to run this maven build you have to issue proper maven command to add this profile. E.g.
mvn clean install -P docker_build -Djavafx-location=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar
To simplify this I made a Docker image using following Dockerfile:
FROM maven:3-jdk-8
RUN apt-get update && \
apt-get install -y --no-install-recommends openjfx
COPY settings.xml /root/.m2/
which uses following maven settings.xml file:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/usr/share/maven/ref/repository</localRepository>
<activeProfiles>
<activeProfile>docker_build</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>docker_build</id>
<properties>
<javafx-location>/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/jfxrt.jar</javafx-location>
</properties>
</profile>
</profiles>
</settings>
I also published it to the Docker hub if somebody may find it useful:
https://hub.docker.com/r/brzigonzales/maven-javafx

Related

How can we add a temporary dependency when running "mvn install" from the command line?

I cannot run my application on my machine unless I add a dependency. Since this is only a hotfix, I do not want to add the dependency on the git repo.
I would like a way to add a temporary dependency, without having to edit the pom.xml everytime I git pull/push.
You can achieve this by using maven profiles.
Just put the dependency that is required only for hotfix on the profile named hotfix and put other dependencies without any profile.
<profiles>
<profile>
<id>hotfix</id>
…
<dependencies>
<dependency>…</dependency>
</dependencies>
…
</profile>
</profiles>
<dependencies>
<dependency>...</dependency>
</dependencies>
To activate the profile supply profile name with -P option on any maven command.
For example, to activate hotfix profile while doing clean and install use command
mvn clean install -Photfix
Also, there are other ways to activate maven profiles.
Please see link for more information: https://maven.apache.org/guides/introduction/introduction-to-profiles.html

Issue in adding third party dependency in Maven during Jenkins build - ODM

I am trying to build ODM projects outside of eclipse using the Jenkins pipeline and Maven plugin. I am following the link : https://www.ibm.com/support/knowledgecenter/en/SSQP76_8.9.0/com.ibm.odm.dserver.rules.designer.run/build_topics/con_buildcmd_intro.html
Though this link works well without the Jenkins pipeline in my local(Windows), but when I try to run the same setup in Jenkins(Linux machine), I am getting the following error :
[WARNING] The POM for com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 is missing, no dependency information available
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # helloWorld:hello-xom:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello XOM/pom.xml, line 19, column 21
[ERROR] Unresolveable build extension: Plugin com.ibm.rules.buildcommand:rules-compiler-maven-plugin:8.10.0.0 or one of its dependencies could not be resolved: Failure to find com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced #
[ERROR] Unknown packaging: decisionservice # helloWorld:hello-main:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello Main Service/pom.xml, line 14, column 16
The pom file which is referred in the above error is as below:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>helloWorld</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>hello-main</artifactId>
<packaging>decisionservice</packaging>
<build>
<plugins>
<plugin>
<groupId>com.ibm.rules.buildcommand</groupId>
<artifactId>rules-compiler-maven-plugin</artifactId>
<configuration>
<deployments>
<deployment>
<name>simple dep</name>
</deployment>
</deployments>
<resolvers>
<resolver>
<!-- The values of the kind and url of the project correspond to the 'kind' and 'url' attribute values of an 'entries' element in the .ruleproject file. -->
<kind>JAVA_PROJECT</kind>
<url>platform:/Hello XOM</url>
<!-- The artifactKey references the groupId and artifactId of a Maven dependency. -->
<artifactKey>${project.groupId}:hello-xom</artifactKey>
</resolver>
</resolvers>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hello-xom</artifactId>
<type>jar</type>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Please let me know if anyone has faced a similar issue or has a possible resolution to the above issue.
Thanks in advance.
Possible resolution: "install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository" ... "on each machine that contains build agents"
To deploy the Build Command Maven plugin to a remote Maven repository, you must configure Maven in your environment. You then use the following command: mvn deploy:deploy-file -Dfile=rules-compiler-maven-plugin.jar -DpomFile=rules-compiler-maven-plugin.pom
This requires access to the Jenkins / Maven server, and at many companies would be done by DevOps.
You install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository.
Deploying the Build Command plugin
You deploy the plugin only once on each machine that contains build agents.
To deploy the Build Command Maven plugin to a remote Maven repository, you must first configure Maven in your environment.
Then, in <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/rules-compiler
 Deploying the annotations archive
If you want to build COBOL projects or projects that use XOM annotations, you must also deploy the annotations archive to your environment before you can build the projects.
In <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/xom-annotation
Source

Questions about pom.xml in Jenkins to run sonarQube through maven project

I'm trying to run sonarQube through Jenkins but I have some difficulties right now. When I build a new job, I use Maven Project and inside the configuration I have to give à pom.xml path but what does it correspond to ?
Thank you in advance
You should find in any jenkins job a post action for sonarqube analyse.
The pom.xml you mention is the pom.xml for your maven project, because sometimes you can put your parent pom.xml in a subdirectory and this is the way for helping jenkins to find it.
Instead of adding Sonar Task to each project why not just configure Sonar at Global Level configuring the settings.xml for your maven configuration, just go to $HOME/someUser/.m2/settings.xml (if you don't have it created yet) with this content:
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://myserver:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
After you you have done that you will be able to run sonar in all the projects this way:
mvn clean verify sonar:sonar
 
# In some situation you may want to run sonar:sonar goal as a dedicated step. Be sure to use install as first step for multi-module projects
mvn clean install
mvn sonar:sonar
 
# Specify the version of sonar-maven-plugin instead of using the latest. See also 'How to Fix Version of Maven Plugin' below.
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar
You may find more information in sonar official documentation:
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven

travis gitflow java maven workflow

I all,
working on a java project hosted on github.
I would like to push the code directly to sonatype on development and master branch.
currently only the develop branch works because I skipped the gpg signing
I use the setting.xml in .travis folder with my credentials
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<!-- Maven Central Deployment -->
<id>ossrh</id>
<username>${env.SONATYPE_USERNAME}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
my travis.yml looks like this:
language: java
jdk:
- oraclejdk8
script:
- mvn --settings .travis/settings.xml clean verify
deploy:
-
provider: script
script:
- mvn --settings .travis/settings.xml deploy -D gpg.skip -P release
on:
branch: develop
-
provider: script
script:
- mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.3:set -D newVersion=$TRAVIS_TAG -P release
- .travis/gpg.sh
- mvn clean deploy --settings .travis/settings.xml -D skipTests=true --batch-mode --update-snapshots -P release
on:
tags: true
my release profile include the deploy plugins needed.
I am getting an error when I push a tag/release (like 0.0.2). I expect this to deploy a release using the tag.
The develop branch works fine and the snapshot is deployed to sonatype repo correctly.
https://github.com/effectus-io/effectus-parent
thanks in advance
here is the travis log error.
The command "mvn --settings .travis/settings.xml clean verify" exited with 0.
Skipping a deployment with the script provider because this branch is not permitted
dpl.0
Fetching: dpl-1.8.31.gem (100%)Fetching: dpl-1.8.31.gem (100%)
Successfully installed dpl-1.8.31
1 gem installed
dpl.1
Installing deploy dependencies
!!! Script support is experimental !!!
Preparing deploy
Cleaning up git repository with `git stash --all`. If you need build artifacts for deployment, set `deploy.skip_cleanup: true`. See https://docs.travis-ci.com/user/deployment/#Uploading-Files.
No local changes to save
dpl.3
Deploying application
No stash found.
/home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/cli.rb:54:in `system': wrong first argument (ArgumentError)
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/cli.rb:54:in `shell'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/provider/script.rb:18:in `push_app'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/provider.rb:146:in `block in deploy'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/cli.rb:41:in `fold'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/provider.rb:146:in `deploy'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/cli.rb:32:in `run'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/lib/dpl/cli.rb:7:in `run'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/gems/dpl-1.8.31/bin/dpl:5:in `<top (required)>'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/bin/dpl:23:in `load'
from /home/travis/.rvm/gems/ruby-1.9.3-p551/bin/dpl:23:in `<main>'
failed to deploy
after much trial and error I realised it is just too much work to try and sign release on travis, there is no good support and that is a shame.
My alternative solution is to use bintray -> https://bintray.com/
it provides a release repo with automate gpg signing of the jars. It also sync with sonatype so I believe this is a complete solution using maven.
in the pom I automated the versioning with the plugin -> https://github.com/effectus-io/effectus-parent/blob/master/pom.xml#L299
notice I do not commit from travis!
I kept the snapshot going directly into sonatype for simplicity ->https://github.com/effectus-io/effectus-parent/blob/master/.travis.yml#L34
you can see my workflow here -> https://github.com/effectus-io/effectus-parent/releases/tag/0.0.10
using gitflow, normal commit to develop branch will automatically push a snapshot to sonatype. Using a release (after tagging) will trigger a build and reversioning using the maven version plugin wich will remove the SNAPSHOT from the pom(s) and deploy to bintray.

How can I exclude a project from a mvn clean install? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I exclude certain modules from a maven build using the commandline
I am running a maven clean install in a pom file which includes several modules (and sub-modules). I was wondering if it is possible to run a maven build but specifying on command line to skip a module from the build ( at the moment I exclude them manually from the build, but Id prefer to do it via command line).
I know that with -pl you can selectively choose projects, but what I would like is to selectively exclude (in a blacklist fashion) some.
You could have a separate <modules> section in a profile, and activate the profile you need in the command line.
Example:
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>...</modules> <!-- module set 1 -->
</profile>
<profile>
<id>profile-2</id>
<modules>...</modules> <!-- module set 2 -->
</profile>
</profiles>
Now, dependent on your current need, execute
mvn install
mvn install -P profile-2
Note that you'd have to think it over carefully, there must be no cross-profile dependencies on the excluded module.

Resources