DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Share Dependencies Between RCP Tycho Driven Project and Plain Maven

Share Dependencies Between RCP Tycho Driven Project and Plain Maven

Lubos Krnac user avatar by
Lubos Krnac
·
Feb. 12, 13 · Interview
Like (0)
Save
Tweet
Share
4.89K Views

Join the DZone community and get the full member experience.

Join For Free

it is well known that rcp bundle is not the maven's best friend. peacemaker between them is maven's plug-in tycho . i was recently migrating my free time rcp based project into maven tycho. my goal was to share dependencies between normal maven project and tycho driven project. plain maven project is needed for running testng tests (testng is not supported by tycho).

there are two approaches how to automatically handle dependencies of eclipse 4 rcp based project driven by tycho:

  • manifest-first - this approach follows standard rcp/osgi dependency mechanisms. all dependencies has to be also assembled into bundles. this is preferred and nicely described in tutorial suggested by tycho's website. it is hosted on github . but there are few problems complicating my goal :

    • it is needed to find existing bundle or create one for every dependency. unhandy.

    • if i would use manifest-first approach, bundle dependencies wouldn't be visible by non tycho maven projects. i would need to have two set of dependencies. redundancy.

  • pom-first – this is alternative approach when dependencies are packed into bundle by maven-bundle-plugin and this is used as dependency to project's bundle. this approach is described here . problem of this approach:

    • it is working only for maven build and dependencies are not picked up by eclipse.

finally got the clue here (in the last approach) and came up with solution that is maybe not that pretty, but the dependencies are specified at one place and even maven as well as eclipse can pick them up. it is using some aspects both mentioned approaches.

i will show here only configuration crucial for my workaround. whole project can be found on google code page . let me describe maven projects structure:


discography-organizer.parent – contains various properties used by child poms. is also used to run build of all sub-modules.

discography-organizer.dependencies.parent – shared dependencies are specified here

discography-organizer.dependencies.bundle – is doing two important steps:

  1. maven-bundle-plugin to pack dependencies

    <plugin>
    	<groupid>org.apache.felix</groupid>
    	<artifactid>maven-bundle-plugin</artifactid>
    	<version>2.1.0</version>
    	<extensions>true</extensions>
    	<configuration>
    		<instructions>
    			<export-package>*; -split-package:=merge-last</export-package>
    		</instructions>
    	</configuration>
    </plugin>
  2. maven-antrun-plugin to copy packed jar with all dependencies into location where it can be picked up by rcp project

    <plugin>
    	<groupid>org.apache.maven.plugins</groupid>
    	<artifactid>maven-antrun-plugin</artifactid>
    	<version>1.7</version>
    	<executions>
    		<execution>
    			<phase>package</phase>
    			<configuration>
    				<target>
    					<copy tofile="${temp.dependencies.folder}/dependencies.jar">
    						<fileset dir="${project.build.directory}" includes="*.jar" />
    					</copy>
    				</target>
    			</configuration>
    			<goals>
    				<goal>run</goal>
    			</goals>
    		</execution>
    	</executions>
    </plugin>

discography-organizer.bundle – main rcp bundle project driven by tycho. expect tycho call, there are two important configurations done:

  1. in plugin.xml configuration on tab “runtime” choose dependency jar created by discography-organizer.dependencies.bundle


  2. pack main project classes into jar. this will be used by testing project discography-organizer.tests

    a) packing of application classes into jar

    <plugin>
    	<groupid>org.apache.maven.plugins</groupid>
    	<artifactid>maven-antrun-plugin</artifactid>
    	<version>1.7</version>
    	<executions>
    		<execution>
    			<phase>package</phase>
    			<configuration>
    				<target>
    					<jar destfile="${temp.dependencies.folder}/${bundle.name}-testing.jar" 
    						basedir="${project.basedir}/bin"/>
    				</target>
    			</configuration>
    			<goals>
    				<goal>run</goal>
    			</goals>
    		</execution>
    	</executions>
    </plugin>

    b) pom file for this test dependency


    <groupid>sk.lkrnac.discorg</groupid>
    <artifactid>discography-organizer.bundle</artifactid>
    <version>testing</version>
    <packaging>jar</packaging>

discography-organizer.tests – normal maven project with tests. it is reading testing classes from jar created by discography-organizer.bundle

<dependency>
	<groupid>sk.lkrnac.discorg</groupid>
	<artifactid>${bundle.name}</artifactid>
	<version>testing</version>
	<scope>system</scope>
	<systempath>${temp.dependencies.folder}/${bundle.name}-testing.jar</systempath>
</dependency>

and that's it. dependencies needed by main bundle or test artifacts are packed into jar files. this workaround has side effects that i really don't like. dependencies are ugly packed in one jar for main bundle. but i can live with that because this approach enables me to combine features of tycho and non-tycho maven plug-ins. i am planning to use another tycho's features (automatic building and junit plug-in tests) and i have good start point for it.

if you can think of some simpler or more elegant solution please don't hesitate to comment it. thanks

Dependency Apache Maven Rich client platform

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Hidden Classes in Java 15
  • Taming Cloud Costs With Infracost
  • Upgrade Guide To Spring Data Elasticsearch 5.0
  • Hackerman [Comic]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: