karaf-maven-plugin: unable to resolve missing requirement osgi.cdi - apache-karaf

I have seen a couple of similar issues reported here but they were either unanswered or with non relevant solutions for my case.
I'm trying to build a maven project using the karaf-maven-plugin. Here is the POM's relevant fragment:
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>${karaf.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>karaf-assembly</id>
<goals>
<goal>assembly</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
<configuration>
<javase>11</javase>
<framework>framework</framework>
<useReferenceUrls>true</useReferenceUrls>
<archiveTarGz>false</archiveTarGz>
<includeBuildOutputDirectory>false</includeBuildOutputDirectory>
<installedBundles>
<installedBundle>mvn:commons-lang/commons-lang/2.6</installedBundle>
<installedBundle>mvn:org.apache.camel/camel-cxf/${camel.version}</installedBundle>
<installedBundle>mvn:org.apache.cxf/cxf-rt-frontend-jaxrs/3.4.0</installedBundle>
<installedBundle>mvn:javax.enterprise/cdi-api/2.0</installedBundle>
<installedBundle>mvn:javax.transaction/javax.transaction-api/1.2</installedBundle>
</installedBundles>
<bootFeatures>
<feature>bundle</feature>
<feature>config</feature>
<feature>diagnostic</feature>
<feature>feature</feature>
<feature>jaas</feature>
<feature>shell</feature>
<feature>log</feature>
<feature>management</feature>
<feature>package</feature>
<feature>shell-compat</feature>
<feature>ssh</feature>
<feature>system</feature>
<feature>wrap</feature>
<feature>scr</feature>
</bootFeatures>
<startupFeatures>
<feature>framework</feature>
<feature>aries-blueprint</feature>
<feature>camel-core</feature>
<feature>camel-blueprint</feature>
</startupFeatures>
<startupBundles>
<bundle>mvn:${project.groupId}/${project.artifactId}/${project.version};start-level=80</bundle>
</startupBundles>
</configuration>
</plugin>
Trying to build, the following exception is raised:
[ERROR] Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.2.8:assembly
(karaf-assembly) on project ...: Unable to build assembly: Unable to resolve root: missing
requirement [root] osgi.identity; osgi.identity=...; type=osgi.bundle; version="
[1.0.1,1.0.1]"; resolution:=mandatory [caused by: Unable to resolve press- release2/1.0.1:
missing requirement [press-release2/1.0.1] osgi.extender; beans=...; filter:="
(&(osgi.extender=osgi.cdi)(version>=1.0.0)(!(version>=2.0.0)))"] -> [Help 1]
So, what obviously happens is that the OSGI extender for CDI (osgi.cdi) is not installed. I probably should add it to the <bootFeatures/> or to the <startupFeatures/> but:
I don't know what's its name 'cause simply saying <feature>cdi</feature> doesn't change anything.
I'm not sure whether it is in <bootFeatures/> or in <startupFeatures/>, or even in <installedFeatures/> that this should be added.
Many thanks in advance.
Seymour

I'm asking my own question: here are the features that need to be installed in order to fix the mentioned exception: pax-cdi, pax-cdi-weld, pax-cdi-web, pax-web-weld.
Kind regards,
Seymour

Related

JMHTest ERROR: Unable to find the resource: /META-INF/BenchmarkList

use Jmh occur enter image description here
even though i change pom
enter image description here
First of all you should move annotation processor to maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
Then if you build the project with IDE you should add annotation processor in IntelliJ settings.
Also I'd upgrade the version of JMH from 1.28 to the latest 1.35.

Exclude LocalDate class for checking by SpotBugs plugin

I'm getting SpotBugs warning with code 'EI_EXPOSE_REP2' for class field
private final LocalDate localDate
I'm trying to exclude this check for java.util.LocalDate class for whole app.
I tried to use annotation #SuppressFBWarnings("EI_EXPOSE_REP2") and it works. But for me this is not good idea of adding this annotation into every place where LocalDate is used. Instead of that I would prefer to add this rule to spotbugs-exclude.xml. And I did so but it's not working (still getting SpotBugs warning). My spotbugs-exclude.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="java.time.LocalDate" />
<Bug code="EI_EXPOSE_REP2" />
</Match>
</FindBugsFilter>
pom.xml
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs.mavenplugin.version}</version>
<executions>
<execution>
<id>spotbugs-verify</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
So my question: how could I exclude SpotBugs checking for specific class in whole app?
Additional question: could we mix up spotbugs-exclude.xml and annotations #SuppressFBWarnings inside the same app? Is SpotBugs able to recognize both configurations?
I have done more investigations and found similar topic here: https://github.com/spotbugs/spotbugs/issues/1601
So looks like for 4.3.0 version SpotBugs plugin has buggy behavior with checking immutable classes and provide warning EI_EXPOSE_REP and EI_EXPOSE_REP2.
So my decision: migrate from 4.3.0 to 4.2.3 - currently all works.

flywaydb: unable to instantiate jdbc driver

The JDBC drivers need to be in an non-classpath directory. I'm using Maven to setup the configuration for Flyway DB and migrate as a goal. I provided in jarDir configuration section the location of the JDBC drivers, but when I execute the migrate goal it still does not recognize the JDBC drivers concerned.
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>sql-enrichment-setup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:postgresql://localhost/enrichment?charSet=utf8</url>
<user>enrichment</user>
<password>enrichment</password>
<schemas>
<schema>public</schema>
</schemas>
<table>schema_history</table>
<initVersion>1.0</initVersion>
<initDescription>Base Migration</initDescription>
<jarDir>/Users/abc/jars</jarDir>
<skip>${skipITs}</skip>
<locations>
<location>
filesystem:${basedir}/integration-test-helpers/sql/enrichment/migrations
</location>
</locations>
</configuration>
</execution>
</executions>
</plugin>
But, when I execute I still get:
Failed to execute goal org.flywaydb:flyway-maven-plugin:3.0:migrate (sql-enrichment-setup) on project esa-core: org.flywaydb.core.api.FlywayException: Unable to instantiate jdbc driver: org.postgresql.Driver
How do I resolve this issue?
jarDir is not a configuration parameter for the Maven Plugin. It is only available in the command-line tool.
In your case you should add the JDBC driver as a dependency to the plugin. This way it won't show up on the application's classpath.

maven-failsafe-plugin won't run on verify and does not find xml on failsafe:verify

The Maven failsafe plugin will not run on my project. If I run mvn verify only surefire runs. If I type mvn failsafe:verify it fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.11:verify (default-cli) on project experiment-server: /home/user/workspace/MyProject-Main/MyProject-IntegrationTest/target/failsafe-summary.xml (The system cannot find the path specified) -> [Help 1]
So I basicly have the same problem as: failsafe plugin won't run on one project but will run on another -- why?
With the difference that my pom already looks like this:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
And this was the solution to this guys problem. Except the solutions on this site didn't work for me. Can someone point out where I messed up?
I also have the problem that I want to start a server with exec-maven-plugin in pre-integration-phase. But when I try mvn-verify it's the very last thing that gets executed.
Just found out for this one, solution is here: http://maven.apache.org/surefire/maven-failsafe-plugin/plugin-info.html
maven-failsafe-plugin, contrarely to maven-compiler-plugin for example, is NOT in the default maven build lifecycle.
Consequently, one must respect this tags hierarchy:
<project>
<build>
<pluginManagement>
<plugins>
<!-- For understanding only, below is the 'maven-compiler-plugin':
its path is 'project -> build -> pluginManagement -> plugins
-> plugin', because it's defaulty part of the maven build
lifecycle: we just 'manage' it -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
..
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- HERE is the 'maven-failsafe-plugin':
its path is 'project -> build -> plugins ->
plugin', because it's NOT defaulty part of
the maven build lifecycle: we have to
'define' it, and not just manage it as
stated earlier -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
..
</plugin>
</plugins>
</build>
<project>
Quoting from the official documentation link: "To define the plugin version in your parent POM" and "To use the plugin goals in your POM or parent POM". One must pay attention to the difference.
I moved my failsafe pom snippet to the parents pom and that seems to do the trick. I have no Idea why.

Getting JNotify into Maven/Archiva

I am currently working on a project that includes using JNotify to monitor when a directory/file has been created, renamed/modified, and deleted. The project is being built in Java 6, not Java 7. JNotify uses JNI to hook into the native OS to monitor the directory/file. My problem is that I need to get JNotify into our repo but I want it to be built so that the java.library.path (DLL) is packaged with the JNI JAR. How would I go about doing that in Maven?
I was able to find the solution I needed using the following maven plugin: http://code.google.com/p/mavennatives/
You must probably upload the jar manually to your archiva instance.
The repository format is fixed, so you will need to perform the rename after retrieving the artifact. That depends how you intend to use it after it is retrieved.
This is a common pattern is something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<stripVersion>true</stripVersion>
</configuration>
<executions>
<execution>
<id>copy-jnotify</id>
<configuration>
<includeArtifactIds>JNotify</includeArtifactIds>
<outputDirectory>${project.build.directory}/my-app</outputDirectory>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
You can use this with the appropriate list of artifacts that will all be copied into the target/my-app directory

Resources