Building iDempiere by tycho

From iDempiere en
Revision as of 10:43, 23 March 2018 by Red1 (talk | contribs) (continue english edits)

Why move to Maven Tycho?

  1. Buckminster is no longer maintained
  2. Maven has huge following

More discussion at IDEMPIERE-3531 and group

Prepare Eclipse to handle Tycho Project

Install Tycho Support

  1. Go to Eclipse Marketplace
  2. Search for Tycho
  3. Choose to install "Tycho Build Tools", "maven tycho utility"

Install m2e Connector

  1. Go to Window/Preferences
  2. Menu Maven/Discovery
  3. Click to open Catalog
  4. On find field type "Tycho"
  5. Choose tycho configurator and install it
  6. Do same for "m2e connector for the maven dependency plugin"

Step to build and setup development environment

  1. Materialize and build (this step use for headless build also use for setup development for eclipse)
    1. Clone source from bitbucket.org to folder [idempiere-home]
    2. Open terminal, cd to [idempiere-home] and execute command "mvn verify"
      • It downloads all libraries on Bundle-ClassPath
      • Compiles all projects
      • Package a binary at [idempiere-home]/org.idempiere.p2/target/products
  2. Setup Eclipse
    1. Import projects
      1. Open Eclipse with Workspace at [idempiere-home]
      2. From Eclipse Menu, choose File/Import
      3. From dialog, choose Maven/Exist maven project
      4. Next dialog, browse to [idempiere-home]
      5. Select all projects and finish dialog
      6. All projects are loaded to workspace
    2. Activate a target file
      1. From Eclipse Menu, choose File/Import
      2. From dialog, choose "Existing projects into workspace"
      3. Choose [idempiere-home]/org.idempiere.p2.targetplatform and click finish
      4. Open a target file org.idempiere.p2.targetplatform/org.idempiere.p2.targetplatform.target is default with remote url
      5. From Target Editor, click to "Set as active target platform"
      6. Wait for Eclipse to download bundles onto target platform
    3. Now your environment is similar to previous Buckminster's.

Config For Jenkins

  1. Setup Maven for Jenkins
  2. Create a Maven Project
  3. In "Source Code Management" Section
    • Repository URL=[[1]] (up to your actual repository)
    • Revision=experimental (up to your actual repository)
  4. On build step, setup with value:
    • Root POM=pom.xml
    • Goals and options=verify

How to set an OSGi Plugin as a Maven Project

  1. Create a normal plugin/feature project on eclipse
  2. Right click to project and choose "Configure/Convert to Maven Project"
  3. In dialog, field "Package" type value depends on type of plug-in
    • Eclipse feature => "Eclipse-feature"
    • Eclipse plugin/fragment => "Eclipse-plugin"
  4. After eclipse has converted project, there will be a pom.xml inside project space, please adjust value as below:
    • Add parent section
      • <parent>
        		<groupId>org.idempiere</groupId>
        		<artifactId>org.idempiere.parent</artifactId>
        		<version>5.1.0-SNAPSHOT</version>
        		<relativePath>../org.idempiere.parent/pom.xml</relativePath>
        	</parent>
        
  5. Open MANIFEST.MF and continue checking..
    • At Runtime tab, section classpath has item "." if not, you should create one
  6. on build.properties
    • Adjust Output to "/target/classes"
    • In case your project has source, make sure it is stated: "source.. = src/"
  7. Reference:

Build Extra Plugin

Build by Run Script from local

  1. Build idempiere core so we have a p2 repository contain all idempiere core also dependency at idempiere/org.idempiere.p2/target/repository
  2. Host this repository to a web server. can use jetty-maven-plugin
  3. Create a maven tycho target plugin point to server setup at step 2
  4. Build extra plugin by use target at step 3

Full example and step by step guideline here

Build by Run Jenkins Job

Because you have to check out from multi repository, I prefer to use jenkins pipeline

Besides, normal pipeline plugin, you have to install "Pipeline Maven Integration Plugin"

For newbie to jenkins pipeline, I suggest to use this tool to generate script http://%5Bjenkins_server%5D/job/%5Bjob_name%5D/pipeline-syntax/

Pipeline syntax.png

Steps to build

  1. Setup a web server (like apache httpd at port 80 on same server jenkin, for access by localhost), assume document dir at /var/www/html
  2. Setup a jenkins job to build idempiere core.
  3. Successful build will copy artifact to /var/www/html/idempiere-core/latest
  4. This is pipeline for build idempiere-core
    node {
       def mvnHome
       stage('Preparation') { // for display purposes
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', revision: 'hsv', source: 'ssh://hg@bitbucket.org/hasuvimex/idempiere', subdir: 'idempiere'])
       }
       stage('Build') {
                
            withMaven(jdk: 'openjdk', maven: 'build-in maven', publisherStrategy: 'EXPLICIT') {
                sh "cd ${WORKSPACE}/idempiere && mvn verify"
            }
            
            sh '''p2OutputDir="${WORKSPACE}/idempiere/org.idempiere.p2/target/repository"
                webDir="/var/www/html/repository/idempiere-hsv-core/latest"
                mkdir -p ${webDir}
                cp -r ${p2OutputDir}/* ${webDir}'''
       }
       stage('Results') {
     
       }
    }
    
  5. Setup other jenkins job to build extra plugin
  6. This's pipeline script
    node {
       def mvnHome
       stage('Preparation') { // for display purposes
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', revision: 'hsv', source: 'ssh://hg@bitbucket.org/hasuvimex/idempiere', subdir: 'idempiere'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', revision: 'hsv', source: 'ssh://hg@bitbucket.org/idplugin/idempiere.maven.tycho.build.extra.bundle', subdir: 'idempiere.maven.tycho.build.extra.bundle'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/hasuvimex/project.extra.bundle', subdir: 'project.extra.bundle'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', revision: 'hsv', source: 'ssh://hg@bitbucket.org/hasuvimex/org.idempiere.customize-feature', subdir: 'project.extra.bundle/org.idempiere.customize-feature'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/idplugin/th.motive.idempiere.base', subdir: 'project.extra.bundle/th.motive.idempiere.base'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/idplugin/th.motive.jasper.report.font', subdir: 'project.extra.bundle/th.motive.jasper.report.font'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/idplugin/th.motive.utility', subdir: 'project.extra.bundle/th.motive.utility'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/hasuvimex/vn.hsv.editor.currencyrate', subdir: 'project.extra.bundle/vn.hsv.editor.currencyRate'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/hasuvimex/vn.hsv.idempiere.base', subdir: 'project.extra.bundle/vn.hsv.idempiere.base'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/hasuvimex/vn.hsv.idempiere.override', subdir: 'project.extra.bundle/vn.hsv.idempiere.override'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/hasuvimex/vn.hsv.jasperreport.install', subdir: 'project.extra.bundle/vn.hsv.jasperreport.install'])
            checkout([$class: 'MercurialSCM', clean: true, credentialsId: 'mainSshKey', source: 'ssh://hg@bitbucket.org/idplugin/th.motive.jasperreport.configuration', subdir: 'project.extra.bundle/th.motive.jasperreport.configuration'])
            
       }
       stage('Build') {
                
            withMaven(jdk: 'openjdk', maven: 'build-in maven', publisherStrategy: 'EXPLICIT') {
                sh  '''
                        ${WORKSPACE}/idempiere.maven.tycho.build.extra.bundle/update.version.sh "/var/www/html/repository/idempiere-hsv-core/latest/plugins" "org.adempiere.base_*.jar"
                    '''
            }
            
            
            sh '''newP2Url="http://localhost/repository/idempiere-hsv-core/latest"
                oldP2Url=http://localhost:8080/idempiere-core
                sed -ri "s|${oldP2Url}|${newP2Url}|g" ${WORKSPACE}/idempiere.maven.tycho.build.extra.bundle/org.idempiere.p2.build.extra.bundle.targetplatform/org.idempiere.p2.build.extra.bundle.targetplatform.target'''
            
            withMaven(jdk: 'openjdk', maven: 'build-in maven', publisherStrategy: 'EXPLICIT') {
                sh '''cd ${WORKSPACE}/idempiere.maven.tycho.build.extra.bundle && mvn verify -Didempiere.target="org.idempiere.p2.build.extra.bundle.targetplatform"'''
            }
       }
       stage('Results') {
     
       }
    }
    
    note: you still have to checkout idempire on this job, because some plugin refer to parent pom on idempiere

Common command

  • mvn verify -P online
    • build idempiere with online profile (will use remote repository for feed all dependency bundle)

Summary about tycho use on idempiere (for full reference tycho API)

[idempiere-root]/pom.xml

setup list of module (bundle) will build with command "mvn -P online"

[idempiere-root]/org.idempiere.parent/pom.xml

  • is parent pom with almost configuration, other bundle will inheritance from this pom
  • profiles
    • Set properties for build condition, current use to setup online and offline repository
  • repositories
    • Setup list of repository use to resolve dependency
    • with P2 repository use "<layout>p2</layout>"
  • dependencies
    • define Osgi bundle feed from maven repositorys

Known Issue

  1. Before step 2.2.1 "On eclipse menu choose file/import", uncheck "project/automatically", because that time the Target Platform is still inactive, so build becomes slow and cannot complete.
  2. Sometimes due to condition in Sourceforge, the active Target Platform ends with errors, hindering a complete clean build. Take a look bellow for tips:
TargetIssue.png

Reference

API to configure tycho

More API to configure tycho plugin

Sync bundle version on manifest with version on pom.xml

Tycho package type

A good summary

Idempiere maven tycho is MANIFEST-First

A complete guide about tycho setup (Must read)

Explain about root-ui for feature

Cookies help us deliver our services. By using our services, you agree to our use of cookies.