Building XP Library : publishToMavenLocal

I created a XP Library from the lib-starter. I wrote some JAVA-Code, the necessary JS-script to run the JAVA Code and some tests for the Code.

I also can successfully build the jar.
I get no error when I publish the lib to the local repo with enonic project gradle publishToMavenLocal.
But the lib does not exist in the repo, which is located at /Users/thomas/.m2

This is my gradle.properties file:

group = org.lienas
projectName = librssj
xpVersion=7.8.0
version=1.0.0-SNAPSHOT

I use the latest CLI and XP-Version. I work on a MAC with M1.

Thomas

Found the following solution. I added the following lines to build.gradle:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

But now I have another problem:
When I call my code inside the lib (unit-test) everything works fine.
When I integrate the lib in an app I get the following error:

2022-04-03 18:37:19,185 ERROR c.e.x.i.task.script.NamedTaskScript - Error executing named task [de.osde.hltest:fetchnews] 'News abrufen' with id 1a7464c1-a0ea-4333-9bc3-7f1fde38f61c: MessageBodyReader not found for media type=application/json;charset=utf-8, type=class org.lienas.feeds.data.Feed, genericType=class org.lienas.feeds.data.Feed.
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json;charset=utf-8, type=class org.lienas.feeds.data.Feed, genericType=class org.lienas.feeds.data.Feed

What would I like to achieve?

I fetch a custom RSS-Feed, which is exposed as JSON. In JAVA I use Jackson to deserialize the JSON and map it with a POJO. Then I make some changes to the data (extract images from content and remove som tags).

Then I serialize back to JSON- using GSON. The API returns the JSON as string .
This is the JAVA-Bridge part from the lib.

const feedReaderBean = __.newBean('org.lienas.feeds.dao.FeedReader');

exports.readFeed = function (uri) {
    const news = feedReaderBean.readFeed(uri);
    return __.toNativeObject(news);
};

Any ideas, why my lib is not working ?

In addition to GSON and Jackson you use Jersey - according to error message.
Jersey is not very OSGi friendly… That explains why it works in unit tests but not in real app.

There should be a simpler way to fetch RSS.

Hi Sergey,

so it is caused by the JAVA-Bridge (what I assumed).

I shifted the fetching part to the consuming JS-Contoller, so that there is no need to deserialize and serialize back in JAVA. I only use the library to extract html tags and clean html using htmlcleaner, as I did not find any npm package for JS, which I could use, due to limtations in Nashorn engine.

I determined that just bundling the Jersey classes without calling the classes where I use them, causes errors in XP.
Thx for your response!

Thomas