(openhabcloud) Repackage .kar causing error

Hi,

Due to a bug in openhabcloud that I need to repackage the bundle’s kar instead of using the readily available bundle. I run the following command after git pull on openhanded-addons, but getting an error which I am not sure how to resolve:

mvn clean install karaf:kar -DskipTests -Dspotless.check.skip=true -Dmaven.test.skip=true -pl :org.openhab.io.openhabcloud

which results the following error:

> [INFO] 
> [INFO] --- karaf-maven-plugin:4.3.4:kar (default-cli) @ org.openhab.io.openhabcloud ---
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time:  26.000 s
> [INFO] Finished at: 2022-08-03T22:58:53+08:00
> [INFO] ------------------------------------------------------------------------
> [INFO] Static code analysis summary report is available in:
> [INFO] file:/home/lsafelix/openhab-3.x.x/git/openhab-addons/target/summary_report.html
> [ERROR] Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.3.4:kar (default-cli) on project org.openhab.io.openhabcloud: Failed to create archive: Failure to find org.openhab.addons.features.karaf:org.openhab.addons.features.karaf.openhab-addons-external:cfg:openhabcloud:3.2.1-SNAPSHOT in https://openhab.jfrog.io/openhab/libs-snapshot was cached in the local repository, resolution will not be reattempted until the update interval of openhab-snapshot has elapsed or updates are forced
> [ERROR] 
> [ERROR] Try downloading the file manually from the project website.
> [ERROR] 
> [ERROR] Then, install it using the command: 
> [ERROR]     mvn install:install-file -DgroupId=org.openhab.addons.features.karaf -DartifactId=org.openhab.addons.features.karaf.openhab-addons-external -Dversion=3.2.1-SNAPSHOT -Dclassifier=openhabcloud -Dpackaging=cfg -Dfile=/path/to/file
> [ERROR] 
> [ERROR] Alternatively, if you host your own repository you can deploy the file there: 
> [ERROR]     mvn deploy:deploy-file -DgroupId=org.openhab.addons.features.karaf -DartifactId=org.openhab.addons.features.karaf.openhab-addons-external -Dversion=3.2.1-SNAPSHOT -Dclassifier=openhabcloud -Dpackaging=cfg -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
> [ERROR] 
> [ERROR] 
> [ERROR]   org.openhab.addons.features.karaf:org.openhab.addons.features.karaf.openhab-addons-external:cfg:3.2.1-SNAPSHOT
> [ERROR] 
> [ERROR] from the specified remote repositories:
> [ERROR]   openhab-release (https://openhab.jfrog.io/openhab/libs-release, releases=true, snapshots=false),
> [ERROR]   openhab-snapshot (https://openhab.jfrog.io/openhab/libs-snapshot, releases=false, snapshots=true),
> [ERROR]   central (https://repo1.maven.org/maven2, releases=true, snapshots=false)
> [ERROR] -> [Help 1]
> [ERROR] 
> [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
> [ERROR] Re-run Maven using the -X switch to enable full debug logging.
> [ERROR] 
> [ERROR] For more information about the errors and possible solutions, please read the following articles:
> [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Generating kars of single addons is not supported. Why do you need a kar?

Unless something changed recently. Generating kar files for single add-ons always worked. It’s useful for bindings that have dependencies specified in the feature XML.

Regarding the error. It looks like you are trying to compile against an older snapshot version. Try against the released version (the one matching your openHAB installation) or git rebase to the latest snapshot.

1 Like

Indeed, even here in community forums other (?) developers suggest utilizing kar files.

I recently built kar files from openhabcloud addon. You can see the detailed steps in release notes (note the expanded section):

As @hilbrand was saying, the ohc.version is an important detail to get right.

Interesting. I never managed to get a correct kar (i.e. including dependencies) for a single add-on.

Using

mvn clean install karaf:kar

in the specific addon folder worked for me in the past without any flaws.

1 Like

as @hilbrand mentioned, we need .kar to load all the dependencies in feature XML. Anyway, this is openhabcloud bundle, which I believe it is .kar anyway.

As for the error, it is due to the following line (****). Remove it seems to compile fine :grin:

<feature name="openhab-misc-openhabcloud" description="openHAB Cloud Connector" version="${project.version}">
		<feature>openhab-runtime-base</feature>
		****<configfile finalname="${openhab.conf}/services/openhabcloud.cfg" override="false">mvn:org.openhab.addons.features.karaf/org.openhab.addons.features.karaf.openhab-addons-external/${project.version}/cfg/openhabcloud</configfile>****
		<bundle dependency="true">mvn:org.json/json/20180813</bundle>
		<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jsr305/3.0.2_1</bundle>
		<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.okhttp/3.8.1_1</bundle>
		<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.okio/1.13.0_1</bundle>
		<bundle dependency="true">mvn:org.openhab.osgiify/io.socket.socket.io-client/1.0.1</bundle>
		<bundle dependency="true">mvn:org.openhab.osgiify/io.socket.engine.io-client/1.0.1</bundle>
		<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.io.openhabcloud/${project.version}</bundle>
	</feature>

Hmm this reminds of me some old issues, as described here Wrong groupId in feature.xml files referencing configs? · Issue #10081 · openhab/openhab-addons · GitHub maybe connected, maybe not

I never got to the root of the issue