OPENRNDR library template
A project template to ease sharing your frequently used classes and extensions. You can publish the library
- locally (to maven local) to use it in various OPENRNDR projects
- online, thanks to jitpack, which takes care of building the library and making it available to other users.
Configuration
Before using this template set the following values:
build.gradle.kts
GitLab and other git hosts
can also be used by jitpack.
You can leave version
unchanged.
group = "com.github.YOUR-USER-NAME"
version = "main-SNAPSHOT"
settings.gradle.kts
rootProject.name = "openrndr-my-library"
This will be the library name when shared online.
Write some code
Place your library code, ideally organized in packages, inside src/main/kotlin/
. A minimal library example:
// src/main/kotlin/Foo.kt
package com.myuser
class Foo {
val bar = 12345
}
Publish
Locally
- Run the
publishToMavenLocal
Gradle task.
Online
- Push this repo including your library code into GitHub, Gitlab or similar.
- Create a git Tag in the web interface for the version you want to distribute.
Using the library
In the project where you want to use your library you need to make two small changes to build.gradle.kts
:
Locally
Use this option while developing your library and your programs.
- Add
mavenLocal()
to therepositories { ... }
block. - Inside the
dependencies { ... }
block, add a reference to your library matching the values you set earlier, for instance:implementation("com.github.YOUR-USER-NAME:openrndr-my-library:main-SNAPSHOT")
. - Reload gradle and wait for indexing.
- The library code should be available in your project:
val foo = Foo()
println(foo.bar)
Online
Use this option to share your library with others.
- Add
maven(url = "https://jitpack.io")
to therepositories { ... }
block. - Inside the
dependencies { ... }
block, add a reference to your library matching the values you set earlier and the Tag you created, for instanceimplementation("com.github.YOUR-USER-NAME:openrndr-my-library:[TAG]")
. - Reload gradle and wait for the library to be created in the jitpack server, then wait to download and index. It can take a few minutes on the first request and even fail to install the library. No worries: just reload Gradle after a few minutes (giving it time to build). Once the library is built downloading it is quick. That should be the experience for users of your library.
- The library code should be available in your project:
val foo = Foo()
println(foo.bar)