How to handle Dependencies in Eclipse Plugin Project using Tycho - eclipse

I'm writing an eclipse plugin and I'd like to manage it using Maven, specifically dependencies.
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.plugin</groupId>
<artifactId>SomePlugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<tycho.version>0.24.0</tycho.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-versions-plugin</artifactId>
<version>${tycho.version}</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>luna</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/luna</url>
</repository>
</repositories>
</project>
I can successfully build this project, however Junit is not visible in my project, I'm not able to call any classes or method from Junit. So it seems I'm not properly using dependencies . Any idea how I can use dependencies? Junit is just an example, no dependency is available to me after a successful build.
I'm a noob to plugins and Maven so any help or guidance would be much appreciated.

You can create a p2 repository from a location of your own filled with jars/plugins/features (also put there jUnit) and then just add that repository to your pom.xml; the external dependency is not a good idea I think, I would recommend using a cached local repository.
How to create p2 repository : http://wiki.eclipse.org/Equinox/p2/Publisher#Features_And_Bundles_Publisher_Application.
Also, when building your Eclipse RCP product, use a custom target platform and also dump in there Eclispe SDK, JUnit+others jars, etc (just google Eclipe target platform)

A very late answer. For those who come on this now, there is the Orbit Eclipse repository which contain a lot of libraries useable with Tycho builds. Junit is one of these.

Related

{Soap UI+ mulesoft} integration for Regression

As part of regression suite I need to trigger the automation soap UI suite post new build is triggered, but I dont have idea to integrate these tools together,
I am not able to find any plugin for soap UI/ready api, so kindly assist me on this....
Mule applications use Maven as a build tool so you can integrate SoapUI tests as part of the Maven build phase. Here is some info on the maven plugin:
https://support.smartbear.com/readyapi/docs/integrations/maven/index.html
Googling Maven Soap UI also returns blog posts on setting this up and some example github repos.
You can follow below steps--
1. Write your test cases in SOAP UI and export the test suite XML.
2. create a maven project and use your test suite details to configure the below POM file.
<projectFile>soapUi-TestSuite File Location</projectFile>
<testSuite>TestSuiteName</testSuite>
<endpoint>endpoint URL</endpoint>
run - mvn clean test
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RegTesting</groupId>
<artifactId>RegTesting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RegTesting</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>Central</id>
<url>http://central.maven.org/maven2/</url>
</repository>
</repositories>
<!-- Plugin repository for test suites generated via soap UI -->
<pluginRepositories>
<pluginRepository>
<id>smartbear-sweden-plugin-repository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.4.0</version>
<configuration>
<projectFile>soapUi-TestSuite File Location</projectFile>
<testSuite>TestSuiteName</testSuite>
<endpoint>endpoint URL</endpoint>
<printReport>true</printReport>
<junitReport>false</junitReport>
<outputFolder>target</outputFolder>
</configuration>
<dependencies>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>forms</artifactId>
<version>1.0.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project> ```

Missing artifact log4j:log4j:bundle:1.2.17

I created a dynamic web application in eclipse Version: Kepler Service Release 1 using menu.
After that I converted it into a maven project using
configure -> convert to maven project. Then I did
maven->Add dependency and then searched for log4j.
After adding that on hovering over the tag
for log4j it displays Missing artifact log4j:log4j:bundle:1.2.17.
I can't update dependencies using maven. How to fix it?
Please also explain the reason for the error.
Here is the generated xml after adding log4j.
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Healthcare</groupId>
<artifactId>Healthcare</artifactId>
<version>0.0.1-HEALTHCARE</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>bundle</type>
</dependency>
</dependencies>
</project>
First why did you changed the default source folder location? The default is src/main/java and for webapp src/main/webapp. Apart from that a bundle for log4j does not exist on Maven Central just remove the <type>bundle</type> from your dependency, cause in Maven Central only a jar is available.
I always do the following trick:
In the dependencies management i edit the dependencies properties (select the dependencies with problem and click on properties button) changing the type from bundled to jar and that fixs the problem.
Well i hope that this solution work for you :) regards,
I too played with all the options provided above but it did not helped. By updating Maven dependencies forcefully my issue got resolved.
Go to project >> Maven >> Update Project
select the project and click OK.
Project will automatically try to download required jar but if still you are getting same error then do below step.
Go to project >> Maven >> Update Project >> check in the checkbox 'Force Update of Snapshots/Releases'
select the project and click OK.
Please check if the dependencies are correct or if it is missing.
<properties>
<springframework.version>4.2.1.RELEASE</springframework.version>
<jackson.version>2.5.3</jackson.version>
<log4j.version>1.2.17</log4j.version>
</properties>
By default (and the common usage), Maven would consume jars as a dependency. Just change the bundle to jar in your pom.xml file in the given dependency which is giving you an error.

How do you pre-compile Drools rules?

I want to pre-compile my .drl files to .class files so they do not have to be compiled a run time. The documentation makes it sounds like the kie-maven-plugin does this, but it is not generating anything for me. It compiles the rules files but does not output anything. Any suggestions?
I'm using the mvn package command, and my pom.xml file is 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie</groupId>
<artifactId>kie-parent-with-dependencies</artifactId>
<version>6.0.1.Final</version>
<!-- relativePath causes out-of-date problems on hudson slaves -->
<!--<relativePath>../droolsjbpm-build-bootstrap/pom.xml</relativePath>-->
</parent>
<packaging>kjar</packaging>
<artifactId>default-kiesession</artifactId>
<name>Drools API examples - Default KieSession</name>
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.0.1.Final</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<repositories>
<!-- Bootstrap repository to locate the parent pom when the parent pom has not been build locally. -->
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
<scm>
<connection>scm:git:git#github.com:droolsjbpm/drools.git</connection>
<developerConnection>scm:git:git#github.com:droolsjbpm/drools.git</developerConnection>
<url>https://github.com/droolsjbpm/drools</url>
</scm>
</project>
There was a bug in 6.0.1.Final that caused the maven plugin to not save the compiled bytecode inside the kjar. It was fixed after, so if you take the 6.0.2-SNAPSHOT (community) version, or the RedHat BRMS 6.0.1.GA (product) version, it will work.
BZ ticket: https://bugzilla.redhat.com/show_bug.cgi?id=1063255
commit that fixes the bug: https://github.com/droolsjbpm/drools/commit/94b9ccf810100c7ec3f8ed186111720ddb2729d3
FYI, when the correct kjar is generated, it contains a kbase.cache file inside the jar for each defined kbase. These cache files contain the compiled bytecode.
It works for me with kie-maven-plugin 6.1.0.Final, but packaging "kjar" should be specified in order to get KIE base cache inside jar file.
It's described in Drools documentation. Just for anybody who find this as first post for 'precompile gdst' on google ;-).
You have to define generateModel=YES when compiling. On mvn command line -DgenerateModel=YES or in pom.xml inside kie-maven-plugin <configuration> secion with <generateModel>YES</generateModel>

mvn install not installing/embedding dependencies

I have been told that the install goal should mean that my resulting jar file will have all required dependencies included into the deployment. This, however, doesn't appear to be working for me.
Here's my pom.xml:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.zone.commandit</groupId>
<artifactId>CommandIt</artifactId>
<version>0.2</version>
<name>CommandIt</name>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<repository>
<id>milkbowl-repo</id>
<url>http://ci.herocraftonline.com/plugin/repository/everything/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.5.2-R1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.2.26-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>se.krka.kahlua</groupId>
<artifactId>kahlua-cldc11</artifactId>
<version>5.1_2.1.0</version>
</dependency>
<dependency>
<groupId>se.krka.kahlua</groupId>
<artifactId>kahlua-core</artifactId>
<version>5.1_2.1.0</version>
</dependency>
<dependency>
<groupId>se.krka.kahlua</groupId>
<artifactId>kahlua-interpreter</artifactId>
<version>5.1_2.1.0</version>
</dependency>
<dependency>
<groupId>se.krka.kahlua</groupId>
<artifactId>kahlua-j2se</artifactId>
<version>5.1_2.1.0</version>
</dependency>
</dependencies>
</project>
From this, I expect a CommandIt-0.2.jar file with commons-io and the kahlua libraries (which are installed in the local repository). The bukkit and Vault dependencies should not be included as they are provided in the runtime environment.
However, upon inspecting the project jar file with 7zip, I find only META-INF and my own source code. What am I doing wrong?
You can use the Maven Assembly plugin to generate a JAR containing all your dependencies.
Add the following in the build > plugins section:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
The Maven target to run this plugin is assembly:single.
Maven dependencies are downloaded to the local maven repository, it is usually .m2 directory in your user home directory. Packaging JAR doesn't include any other JARs into the result. If you want to make a web application, use packaging WAR (or EAR). In the WAR file there are your JARs inc. all dependencies included.
mvn install executes plugins which simply put whatever artifacts were built, in this case a JAR file with your code, into your local repository, typically located at ~/.m2/repository.
If you want to assemble something to distribute, like a tarball containing JARs and shell scripts, looking into the Maven assembly plugin. If you want to assemble a single JAR file containing your code and the code in your dependencies, the Maven assembly plugin can be run using the jar-with-dependencies descriptor.

Dependencies from pom.xml not considered by Eclipse in Tycho Project

I created a Tycho project with an eclipse-plugin packaging. The project includes some dependencies that are specified via pom.xml. The relevant pom sections are:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tycho.version>0.15.0</tycho.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>juno</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/juno</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>com.springsource.org.testng</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>com.google.guice</groupId>
<artifactId>com.springsource.com.google.inject</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.aopalliance</groupId>
<artifactId>com.springsource.org.aopalliance</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
And the Manifest is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin-project-pure
Bundle-SymbolicName: plugin-project-pure
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.equinox.app,
org.eclipse.uml2.uml;bundle-version="4.0.0",
org.eclipse.uml2.uml.resources;bundle-version="4.0.0",
org.junit;bundle-version="4.10.0",
com.springsource.org.testng;bundle-version="[6.4.0,6.4.0]"
The project only consists of a class in the default package that uses an annotation from org.testng.annotations to test that during compilation the dependency is included.
If I'm building the project on the command line with Maven 3.0.4 everything works fine. After importing the project in Eclipse Juno, I get multiple errors. The most important one is in the manifest and it states that the bundle com.springsource.org.testng can't be resolved. There is also a compile error in the class, because the import of the annotation is not possible. The project has the Maven Nature configured. Am I missing something so that Eclipse Juno will also consider the dependencies of the pom?
You can circumvent this problem splitting your project build into two parts:
First, aggregate your POM dependencies into a p2 repository. You'll need an eclipse-feature and an eclipse-repository module for this, plus a separate parent POM that lists the POM dependencies and configures pomDependencies=consider.
In the second build, add the p2 repository from the first build to the target platform, e.g. via a jar:file: URL pointing to the build result in your local Maven repository.
Then, you can also configure your target platform in Eclipse to include the p2 repository from the first build (which depends on how you currently configure it). You'll get the best consistency between Tycho and Eclipse if you use a so-called target definition file, which you can use both as target platform in Eclipse and in Tycho.
I am aware that all this is quite a bit of effort to set up, but AFAIK there are no better solutions that fully work.
The most elegant solution to all problems that exist between maven-RCP problems is to use the
p2-maven-plugin. Here is the brief summary of those problems (cuts from the link above):
In order to add a third-party dependency to an Eclipse RCP project the
dependency has to reside in a P2 update site.
Eclipse (and other providers) provide a set of public update sites,
but obviously not all popular and publicly available dependencies are
there (that is the problem number #1).
Since Eclipse RCP is an OSGi environment in order to add a dependency
to a p2 update site the depenedncy has to be an OSGi bundle (that is
the problem number #2).
So, let’s sum up for now: all our artifacts have to be OSGi bundles,
but they are not always bundles and they have to be located in a P2
site, but we do not have that site. How do we proceed then?
It is not that difficult, there is a ‘bnd’ tool written by Peter
Kriens that can transform your jars into bundles. There is also a
convenience tool provided by Eclipse RCP that can generate a P2 site
(in a cumbersome and painful way though). Both tools assume that all
your jars/bundles are located in a local folder - which means that you
have to download them by-hand. You could use Maven to automate it a
bit, but there is a significant difference in the way how Maven
calculates a dependency tree and this is not alwyas compatible with
the OSGi way (that is the problem number #3). Let us elaborate on it a
bit more.
It allows you to define a pom-packaged project that will resolve all maven dependencies, convert all non-OSGi ones to bundles and generate a p2 site from them.
Below is the full minimal pom file including the dependency on slf4j-log4j12 (which implicitly depends on both slf4j and log4j v1.2):
<?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>
<groupId>me.berezovskiy.project</groupId>
<artifactId>p2</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>1.1.1-SNAPSHOT</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<artifacts>
<artifact>
<id>org.slf4j:slf4j-log4j12:1.7.7</id>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.12.v20130726</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>${basedir}/target/repository/</webAppSourceDirectory>
<webApp>
<contextPath>/site</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>reficio</id>
<url>http://repo.reficio.org/maven/</url>
</pluginRepository>
</pluginRepositories>
</project>
P.S. I usually do not post answers to old and answered questions, but in my case it took so long to resolve this issue in a clean and elegant way that I decided to write about it. Additionally, the solution has appeared in late 2013.
from the command line navigate to the folder where the pom.xml is located.
Run mvn eclipse:eclipse.
This should build a valid eclipse project.