Git Product home page Git Product logo

gradle-karaf-plugin's Introduction

gradle-karaf-plugin

gradle karaf plugin badge :license apache brightgreen nw.js

Features

  • ✓ Karaf features

  • ✓ Karaf KAR

  • ❏ Karaf custom distribution

  • ❏ Nice documentation

Tasks

Automatically generate Karaf feature file in /build/karaf/features

gradle generateFeatures

Automatically generate Karaf kar file in /build/karaf/kar

gradle generateKar

Description

The gradle-karaf-plugin is designed to automate the process of creating Apache Karaf feature and kar files.

This plugin generates the desired karaf files by utilizing the native gradle configurations mechanism. As gradle automatically determines all direct and transitive dependencies, a complete list of dependencies is provided to the plugin for a given set of configurations.

As OSGi can only install bundles, standard jars must be wrapped to add necessary manifest information specifying the jar’s import and export packages. To simply this process Karaf provides a native wrap tool that can be run during jar/bundle installation. This plugin determines if each dependency is already a bundle and adds the wrap tag if it is not (see example below).

Notes

  • Considering that gradle automatically "promotes" dependency version conflicts, only a single version of a dependency is avalible per each gradle configuration. As OSGi bundles can mandate certain versions of dependencies, it is likely that multiple versions of a jar/bundle are needed. In this case, it is recommended to add another gradle configuration, perhaps "karaf", and specify the other dependency version under this new configuration. Include both configurations to the karaf→features→feature→configurations statement (see example below). This will result in both versions of the dependency being added to the feature/kar file.

  • Karaf 4 support requires the xsd version be at least 1.3.0

  • This plugin is an extension of the previous gradle-karaf-feature-plugin

Requirements

  • Gradle 3.0+

Usage

apply plugin: 'com.github.lburgazzoli.karaf'

buildscript {
    dependencies {
        classpath "gradle.plugin.com.github.lburgazzoli:gradle-karaf-plugin:0.0.46"
    }
}

repositories {
    mavenCentral()
}

Example

build.gradle

plugins {
    id 'maven'
    id 'java'
    id 'com.github.lburgazzoli.karaf' version '0.0.46'
}

repositories {
    mavenCentral()
}

group   = 'com.github.lburgazzoli'
version = '0.0.1'

configurations {
    commons
    json
    rest
    square
    hazelcast

    // This will avoid adding transitive dependencies
    ariesBlueprint {
        transitive = false
    }
}

dependencies {
    runtime 'com.google.guava:guava:19.0'
    commons 'commons-io:commons-io:2.4'

    json 'com.fasterxml.jackson.core:jackson-core:2.7.0'
    json 'com.fasterxml.jackson.core:jackson-databind:2.7.0'
    json 'com.fasterxml.jackson.core:jackson-annotations:2.7.0'

    square 'com.squareup.retrofit2:retrofit:2.0.0'

    ariesBlueprint 'org.apache.aries.blueprint:org.apache.aries.blueprint.api:1.0.1'
    ariesBlueprint 'org.apache.aries.blueprint:org.apache.aries.blueprint.cm:1.0.8'
    ariesBlueprint 'org.apache.aries.blueprint:org.apache.aries.blueprint.core.compatibility:1.0.0'
    ariesBlueprint 'org.apache.aries.blueprint:org.apache.aries.blueprint.core:1.6.0'
    ariesBlueprint 'org.apache.karaf.bundle:org.apache.karaf.bundle.blueprintstate:4.0.4'

    hazelcast 'org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1'
    hazelcast 'com.eclipsesource.minimal-json:minimal-json:0.9.2'
    hazelcast 'com.hazelcast:hazelcast-all:3.6.1'
}

karaf {
    features {
        // See section below for karaf 4 support if using 1.3.0
        xsdVersion  = '1.2.0'
        version     = '4.0.0' // Your project version
        description = 'Karaf features'

        // Include the current project, false by default
        includeProject = false

        // Define a feature named 'common' with dependencies from runtime
        // configuration (default) and commons
        feature {
            name        = 'common'
            description = 'Common dependencies'

            // Include one or more additional configuration
            configuration 'commons'
        }

        // Define a feature named 'rest' with dependencies from json and square
        // configurations
        feature {
            name        = 'rest'
            description = 'REST dependencies'

            // Override configurations
            configurations 'json', 'square'
        }

        feature {
            name        = 'aries-blueprint'
            description = 'Aries Blueprint'

            // Override configurations
            configurations 'ariesBlueprint'

            // Add feature dependency (newest)
            feature 'aries-proxy'

            // Customize artifacts with group 'org.apache.aries.blueprint'
            bundle ('org.apache.aries.blueprint') {
                attribute 'start-level', '20'
            }

            // Customize artifacts with group 'org.apache.karaf.bundle'
            bundle ('org.apache.karaf.bundle') {
                attribute 'start-level', '30'
            }

            conditional('bundle') {
                bundle 'org.apache.karaf.bundle:org.apache.karaf.bundle.blueprintstate'
            }

            capability('osgi.service') {
                effective = 'active'
                extra     = 'objectClass=org.apache.aries.blueprint.services.ParserService'
            }

            capability('osgi.extender') {
                extra     = 'osgi.extender="osgi.blueprint";uses:="org.osgi.service.blueprint.container,org.osgi.service.blueprint.reflect";version:Version="1.0"'
            }
        }

        // Define a feature named 'hazelcast'
        feature {
            name        = 'hazelcast'
            description = 'In memory data grid'

            configurations 'hazelcast'

            // Add configFile entry
            configFile {
                filename = "/etc/hazelcast.xml"
                uri      = "mvn:org.apache.karaf.cellar/apache-karaf-cellar/${project.version}/xml/hazelcast"
            }

            // Add configFile entry and copy a local file to the kar repository
            configFile {
                filename = "/etc/hazelcast-clustered.xml"
                file     = file("etc/hazelcast-clustered-defaults.xml")
                uri      = "mvn:org.apache.karaf.cellar/apache-karaf-cellar/${project.version}/xml/hazelcast-clustered"
                override = true // (optional) Override existing configuration files within karaf. False by default
            }
        }
    }

    // Enable generation of Karaf Archive KAR based on features defined above.
    // To generate kar either use generateKar, assemble or install
    kar {
        // Optionally set the kar name, default is:
        //
        //     ${features.name}-${features.version}.kar
        //
        // Extension is automatically set to .kar
        archiveName = 'foo'
    }
}

Generated Result from "gradle generateFeatures"

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="gradle-karaf-features-plugin-examples">
  <feature name="common" version="0.0.1" description="Common dependencies">
    <bundle>mvn:com.google.guava/guava/19.0</bundle>
    <bundle>mvn:commons-io/commons-io/2.4</bundle>
    <capability></capability>
  </feature>
  <feature name="rest" version="0.0.1" description="REST dependencies">
    <bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.7.0</bundle>
    <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/2.7.0</bundle>
    <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.7.0</bundle>
    <!--
        as squareup's jars a re not OSGi ready, the plugin automatically adds wrap instruction
    -->
    <bundle>wrap:mvn:com.squareup.okio/okio/1.6.0</bundle>
    <bundle>wrap:mvn:com.squareup.okhttp3/okhttp/3.2.0</bundle>
    <bundle>wrap:mvn:com.squareup.retrofit2/retrofit/2.0.0</bundle>
    <capability></capability>
  </feature>
  <feature name="aries-blueprint" version="0.0.1" description="Aries Blueprint">
    <feature>aries-proxy</feature>
    <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/1.0.1</bundle>
    <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.cm/1.0.8</bundle>
    <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core.compatibility/1.0.0</bundle>
    <bundle start-level="20">mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core/1.6.0</bundle>
    <conditional>
      <condition>bundle</condition>
      <bundle start-level="30">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.blueprintstate/4.0.4</bundle>
    </conditional>
    <capability>osgi.service;effective:='active';resolution:='mandatory';objectClass=org.apache.aries.blueprint.services.ParserService,osgi.extender;effective:='resolve';resolution:='mandatory';osgi.extender="osgi.blueprint";uses:="org.osgi.service.blueprint.container,org.osgi.service.blueprint.reflect";version:Version="1.0"</capability>
  </feature>
  <feature name="hazelcast" version="1.2.3" description="In memory data grid">
    <configfile filename="/etc/hazelcast.xml">mvn:org.apache.karaf.cellar/apache-karaf-cellar/1.2.3/xml/hazelcast</configfile>
    <configfile filename="/etc/hazelcast.xml">mvn:org.apache.karaf.cellar/apache-karaf-cellar/1.2.3/xml/hazelcast-clustered</configfile>
    <bundle>mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
    <bundle>mvn:com.eclipsesource.minimal-json/minimal-json/0.9.2</bundle>
    <bundle>mvn:com.hazelcast/hazelcast-all/3.6.1</bundle>
  </feature>
</features>

Karaf 4 Support

Karaf 4 features xsd v1.3.0 partially supported

<feature version="1.2.3" dependency="true">dependent-feature</feature>

To generate this stuff

  1. Set xsdVersion to 1.3.0

  2. Use dependency with configuration closure

karafFeatures {
  name = 'featuresName'
  xsdVersion = '1.3.0'
  outputFile = file("${project.buildDir}/karaf/features/${project.name}-feature.xml")
  features {
    mainFeature {
      name = 'main-feature-name'
      feature('dependent-feature') {
        dependency = true              //false by default
        version = "1.2.3"              //empty by default
      }
    }
  }
}

generated file build/karaf/features/project1-feature.xml will look like below

<features xmlns='http://karaf.apache.org/xmlns/features/v1.3.0' name='featuresName'>
  <feature name='main-feature-name' version='1.0.0'>
    <feature version="1.2.3" dependency="true">dependent-feature</feature>
  </feature>
</features>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.