diff --git a/.github/workflows/gradle_publish.yml b/.github/workflows/gradle_publish.yml
new file mode 100644
index 0000000000..61e06d210e
--- /dev/null
+++ b/.github/workflows/gradle_publish.yml
@@ -0,0 +1,21 @@
+name: Publish package to GitHub Packages
+on: workflow_dispatch
+jobs:
+ publish:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ packages: write
+ steps:
+ - uses: actions/checkout@v5
+ - uses: actions/setup-java@v4
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ - name: Setup Gradle
+ uses: gradle/actions/setup-gradle@017a9effdb900e5b5b2fddfb590a105619dca3c3 # v4.4.2
+
+ - name: Publish package
+ run: ./gradlew publish
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/README.md b/README.md
index fd5eda434b..bba7ada362 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,45 @@ You can also go to this [Demo Page](http://opensensorhub.github.io/osh-js/latest
This other [Technical Page](http://sensiasoft.net:8181/demo.html) contains example SWE service calls for you to see the standard compliant XML and data that OSH generates.
+If using a build system, binaries for osh-core are stored in GitHub Packages. Use the following repository setup to resolve dependencies:
+
+### Gradle
+
+```groovy
+//build.gradle
+repositories {
+ maven {
+ url = uri("https://maven.pkg.github.com/opensensorhub/osh-core")
+ credentials {
+ username = System.getenv("GITHUB_ACTOR")
+ password = System.getenv("GITHUB_TOKEN")
+ }
+ }
+}
+ ```
+### Maven
+```xml
+
+
+
+ osh-core
+ osh-core
+ https://maven.pkg.github.com/opensensorhub/osh-core
+
+
+```
+```xml
+
+
+
+ osh-core
+ ${env.GITHUB_ACTOR}
+ ${env.GITHUB_TOKEN}
+
+
+```
+Where environment variables `GITHUB_ACTOR` and `GITHUB_TOKEN` are your GitHub username and PAT respectively.
+[Instructions on how to generate PATs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
## Building
diff --git a/common.gradle b/common.gradle
index 3560fd1e63..43a41daaec 100644
--- a/common.gradle
+++ b/common.gradle
@@ -14,22 +14,22 @@ buildscript {
}
}
-
-allprojects {
+
+allprojects {
group = 'org.sensorhub'
repositories {
- maven { url "https://repo.maven.apache.org/maven2" }
+ mavenCentral()
}
// set build number to HEAD SHA-1
def stdout = new ByteArrayOutputStream()
exec {
- commandLine('git','rev-parse','--short','HEAD')
- standardOutput = stdout
- // hide errors and don't throw exception if not a git repo
- errorOutput = new ByteArrayOutputStream()
- ignoreExitValue = true
+ commandLine('git', 'rev-parse', '--short', 'HEAD')
+ standardOutput = stdout
+ // hide errors and don't throw exception if not a git repo
+ errorOutput = new ByteArrayOutputStream()
+ ignoreExitValue = true
}
ext.buildNumber = "$stdout".trim()
@@ -64,7 +64,7 @@ subprojects {
eclipse {
classpath {
downloadJavadoc = true
- file.whenMerged {
+ file.whenMerged {
entries.each {
if (it.hasProperty('exported'))
it.exported = true
@@ -72,7 +72,7 @@ subprojects {
}
}
}
-
+
// custom dependency configurations for embedding jars in OSGi bundle
configurations {
embeddedApi
@@ -82,13 +82,13 @@ subprojects {
api.extendsFrom(embeddedApi)
implementation.extendsFrom(embeddedImpl)
}
-
+
// default test dependencies
dependencies {
testImplementation 'junit:junit:4.13'
testImplementation 'xmlunit:xmlunit:1.6'
}
-
+
// print test names
test {
testLogging {
@@ -118,8 +118,8 @@ subprojects {
ext.getPackagesFromJar = { jarFile, packageSet ->
//println jarFile
FileSystems.newFileSystem(jarFile.toPath(), ClassLoader.getSystemClassLoader()).withCloseable { fs ->
- def rootDir = fs.getPath('/')
- getPackagesFromDir(rootDir, packageSet)
+ def rootDir = fs.getPath('/')
+ getPackagesFromDir(rootDir, packageSet)
}
}
@@ -141,10 +141,10 @@ subprojects {
// of the manifest files
if (rootDir.relativize(dir).toString().contains('\\')) {
packageSet.add(rootDir.relativize(dir).toString()
- .replace('\\', '.') + '.*')
+ .replace('\\', '.') + '.*')
} else {
packageSet.add(rootDir.relativize(dir).toString()
- .replace('/', '.') + '.*')
+ .replace('/', '.') + '.*')
}
}
}
@@ -152,13 +152,15 @@ subprojects {
// help method to automatically find osgi activator class
ext.findActivator = {
- for (def classDir: sourceSets.main.output.classesDirs) {
+ for (def classDir : sourceSets.main.output.classesDirs) {
def rootDir = classDir.toPath()
def activatorClass = Files.walk(rootDir)
.filter { it.toString().endsWith('Activator.class') }
- .map { rootDir.relativize(it).toString()
- .replace(java.io.File.separatorChar, (char)'.')
- .replaceAll('.class$', '') }
+ .map {
+ rootDir.relativize(it).toString()
+ .replace(java.io.File.separatorChar, (char) '.')
+ .replaceAll('.class$', '')
+ }
.findAny()
.orElse(null)
if (activatorClass)
@@ -176,10 +178,10 @@ subprojects {
// ignore some common errors
attributes '-fixupmessages': 'Classes found in the wrong directory; is:=ignore,' +
- 'Unused Import-Package instructions; is:=ignore,' +
- 'The default package \'.\' is not permitted by the Import-Package syntax; is:=ignore,' +
- 'Unused Export-Package instructions; is:=ignore,'
-
+ 'Unused Import-Package instructions; is:=ignore,' +
+ 'The default package \'.\' is not permitted by the Import-Package syntax; is:=ignore,' +
+ 'Unused Export-Package instructions; is:=ignore,'
+
// disable DS annotation processing
if (!attributes['-dsannotations'])
attributes '-dsannotations': '!*'
@@ -292,9 +294,23 @@ subprojects {
assemble.dependsOn osgi
+ tasks.register('prePublish') {
+ if (System.getenv("GITHUB_ACTOR") == null) {
+ throw new Exception("Environment variable GITHUB_ACTOR not set. Please set to your github username.")
+ }
+
+ if (System.getenv("GITHUB_TOKEN") == null) {
+ throw new Exception("Environment variable GITHUB_TOKEN not set. Please generate and set to your personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens")
+ }
+ }
+
+ tasks.named('publish') { // This is a lifecycle task that runs all publish tasks
+ dependsOn 'prePublish'
+ }
+
// do stuff at the end in case subprojects add extra info
afterEvaluate { project ->
-
+
// set defaults for some OSGi manifest entries
project.osgi {
manifest {
@@ -320,9 +336,10 @@ subprojects {
from project.osgi.manifest
}
}
-
+
// maven artifact content
project.publishing {
+
publications {
mavenJava(MavenPublication) {
from components.java
@@ -352,20 +369,30 @@ subprojects {
} >> project.pom)
}
}
- }
+ }
+ repositories {
+ maven {
+ name = "GitHubPackages"
+ url = "https://maven.pkg.github.com/opensensorhub/osh-core"
+ credentials {
+ username = System.getenv("GITHUB_ACTOR")
+ password = System.getenv("GITHUB_TOKEN")
+ }
+ }
+ }
}
}
-
+
// disable jar task if no source is included
if (!new File(project.projectDir, 'src').exists()) {
- tasks.osgi.enabled = false
+ tasks.osgi.enabled = false
tasks.jar.enabled = false
}
// custom task to install in local maven repo
task install
install.dependsOn(build)
- install.dependsOn(publishToMavenLocal)
+ install.dependsOn(publishToMavenLocal)
}