Giter Club home page Giter Club logo

gradle-reflections-plugin's Introduction

Gradle Reflections Plugin Build Status

The plugin uses Reflections to scan and index your project classes at build-time, allowing run-time querying without the indexing performance hit.

Usage

The idea is to use the plugin with Gradle to embed a pre-scanned metadata index in your jar, then utilise the embedded index at ruintime using Reflections.collect(). See the Gradle and Java sections bellow
for an example.

Gradle

The plugin is published in Gradle plugin portal, so it is rather easy to use. This will add the pre-scanned metadata index in your jar as META-INF/reflections/PROJECTNAME-reflections.xml, with PROJECTNAME substituted by your actual project name.

// import the reflections plugin
plugins {
	id "io.github.manosbatsis.gradle.plugin.reflections" version "1.1"
}

// you probably need this...
apply plugin: 'java'

// reflections plugin needs the compiled
// project classes, so either chain tasks
// with dependsOn as bellow or execute tasks explicitly
// when using the command line
reflections{
    dependsOn classes
}
jar{
    dependsOn reflections
}


// Use jcenter for resolving your dependencies.
repositories {
	jcenter()
}

// Add Reflections and dom4j dependencies
dependencies {
	compile 'org.reflections:reflections:0.9.10'
	compile 'dom4j:dom4j:1.6.1'
	testCompile 'junit:junit:4.12'
}

Java

To utilise the pre-scanned index simply create a Reflections instance as:

// Collect and merge pre-scanned Reflection xml resources
// and merge them into a Reflections instance
Reflections reflections = Reflections.collect();
// use the instance, e.g.
reflections.getSubTypesOf(Foobar.class);

Development

You don't need this to use the plugin. This section is meant for developers that want to build the plugin code themselves.

Quickstart

This section assumes you have a JDK and a recent Gradle installed and available in your path.

Clone:

git clone https://github.com/manosbatsis/gradle-reflections-plugin.git

Build:

gradle build

Tests

The build has some unit and integration tests. The build creates the report at build/reports/tests/test/index.html:

gradle-reflections-plugin's People

Contributors

manosbatsis avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

walec51

gradle-reflections-plugin's Issues

Make usable in tests

It would be nice to have an option to also generate the xml for testClasses. Without this I cannot test code depended on this library and classes available only in test.

Dependency issues

I added the plugin into my build.gradle file as I saw it here. Here is the complete build.gradle file:

plugins {
    id "io.github.manosbatsis.gradle.plugin.reflections" version "1.1"
}

apply plugin: 'java'

reflections {
    dependsOn classes
}
jar {
    dependsOn reflections
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.avaya.mobilevideo"
        minSdkVersion 24
        targetSdkVersion 26

        //jackOptions {
        //    enabled true
        //}
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
    }
}

dependencies {
    api 'com.android.support:support-v4:26.1.0'
    implementation 'org.reflections:reflections:0.9.11'
    implementation 'dom4j:dom4j:1.6.1'
    implementation files('libs/avaya-client-sdk-android-3.4.1.jar')
    implementation files('libs/android-logging-log4j-1.0.3.jar')
    implementation files('libs/log4j-1.2.17.jar')
}

The rest of the stuff was already part of the file (this is a sample project that was provided by vendor). When synchronizing, I got this error:

The 'java' plugin has been applied, but it is not compatible with the Android plugins.

When I remove the java plugin, I get another error:

Could not get unknown property 'classes' for task ':app:reflections' of type io.github.manosbatsis.gradle.plugin.reflections.ReflectionsMetadataEmbeddingTask.

How to proceed from here?

Fix and document detailed extention/config

Reflections configuration includes package names, scanners, classloaders, serialisers etc. Those should be fixed, tested and documented for advance usage via the plugin

Add task dependency programmatically

Currently users of the plugin are forced to explicitly run tasks the plugin depends on (i.e. classes) or chain tasks in build.gradle using dependsOn. Adding the dependency programmatically would make the plugin task easier to use.

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.