Best practice developing a LIBRARY for reuse?

Enonic version: 6
OS: Ubuntu

I have some reusable code that I want to put in a libray. Is there any how to guide how I can develop the library and use it in an feature project at the same time ?

Links and which direction I should go are welcome :smile:

//runar

1 Like

Hi.

Itโ€™s not any guide out there yet on creating a reusable library. But, itโ€™s the same as creating any other JAR based-build. The best thing to do is to create 2 seperate projects (optionally with a parent-project) - one for the lib and one for the app that uses the lib.

root-project/
  mylib/
    src/...
    build.gradle
 myapp/
   src/...
   build.gradle
build.gradle
settings.gradle

See how to use multi-module projects here: https://docs.gradle.org/current/userguide/multi_project_builds.html. The build.gradle for myapp is the same as any other app, except you can then include your lib as include project(':mylib').

... 
apply plugin: 'com.enonic.xp.app'
...

dependencies {
   include project(':mylib')
   ...
}

mylib build-file is much simpler since itโ€™s only going to build a JAR.

apply plugin: 'java'

depenedncies {
    ...
 }

Hope this helps.

BR,
Sten Roger

1 Like