All building blocks are stored within Eclipse projects.
You can mark projects as libraries. Do this either when you create a new project (by selecting ‘library’), or when sharing a project for the first time.
Libraries are intended for blocks that are useful in many applications, and that are reusable. You can group blocks related to similar functions or technologies into the same libraries. For instance, there is a library with blocks related to timers, and a library for several blocks to send data via MQTT.
Technically, libraries are similar to projects, with the following differences:
When imported, libraries are not unwrapped into the workspace but stay within their compact archive. Therefore, when a user imports a library, they are read-only. It is still possible to duplicate blocks from libraries, but they are copied into a new project.
Libraries do not contain applications, only blocks that can be used by other blocks or applications.
Libraries must only depend on other libraries, not other projects.
In principle, you only need a single project. This project contains the application building block. It can also contain all other building blocks for that application.
You should place blocks that are useful for others into their own projects or libraries. For instance, if your application uses blocks that make a specific sensor usable, you can place all blocks related to that sensor into their own project and then convert this project into a library when sharing it. Make sure, however, that none of the blocks have a dependency back to the project with the application.
You can create additional projects for your application. However, be careful not to make things more complicated than necessary:
It may be more elaborate for colleagues to download several projects instead of a single one, and it’s easy to loose overview if an application is distributed among several projects. An exception are libraries for specific functions, which you should always build as independent as possible.
There must not be circular dependencies among projects. This means, project P1 can depend on blocks of project P2, but then P2 cannot depend on blocks from P1. The dependency graph of a project always needs to be a tree.
Restructuring a project and moving building blocks can be a bit tricky, because of all the dependencies, both among the blocks and also the Java code.
The easiest is to duplicate a block into a new project or library.
Right-click the block in the Blocks view, and select Duplicate… Select the new library or project that should contain the block.
Make sure that the Java code of the duplicated block is okay, and especially that it does not depend on types that are defined in the original project.
Exchange all references to the original block. You can Right-click the original block, and select Search / References to this Block. This lists all blocks that still refer to this block. Exchange these references to the new building block, by selecting the referred block and click on Set Building Block…
Delete the old building block.