You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2019/08/30 22:52:32 UTC

How to make karaf-maven-plugin exclude some compile depencies when building a feature?

Is it possible to make karaf-maven-plugin exclude some dependencies with
<scope>compile</scope>?

I'm trying to create a pull request to fix this issue
 https://github.com/pgjdbc/pgjdbc/issues/1552
and the PostgreSQL JDBC driver pulls in and includes two dependencies,
that I would like to not pull in with the feature.

Firstly, the aren't needed (since they are embedded into the psql jar).
Secondly, they aren't OSGi bundles, so karaf wraps them:
51 │ Active │  80 │ 0               │ wrap_file__home_sb_.m2_repository_com_github_waffle_waffle-jna_1.9.1_waffle-jna-1.9.1.jar
52 │ Active │  80 │ 0               │ wrap_file__home_sb_.m2_repository_com_ongres_scram_client_2.0_client-2.0.jar

Thanks!


Re: How to make karaf-maven-plugin exclude some compile depencies when building a feature?

Posted by Ryan Moquin <fr...@gmail.com>.
I agree about the messy part with blacklisting.  It's a good way to keep
from being blocked from an issue you otherwise can't around, is how I look
at it.

I guess I hope that eventually there will be an awareness by developers
around putting a little more thought into code organization and
dependencies.  I think tools and convenience have caused a lack of
awareness which has only caused nonmodular libraries and unnecessary
dependencies.  Karaf features definitely helps to alleviate that for sure.

Ryan

Ryan

On Sun, Sep 1, 2019, 3:11 AM Steinar Bang <sb...@dod.no> wrote:

> >>>>> Ryan Moquin <fr...@gmail.com>:
>
> > Hi Steinar,
> > There are a couple ways.
>
> > 1. You can use <scope>runtime</scope> to prevent a jar from being added,
> > but that has other ramifications when building (such as I think unit test
> > code won't see the dependency)
> > 2. You can use <scope>provided</scope> to only include that dependency
> but
> > not of it's transitive dependencies in the feature.xml
>
> Yup, but I didn't want to touch their dependencies if I could avoid it.
>
> > 3. The karaf maven plugin has an option to excludeArtifactId (look in the
> > docs of the karaf site)
>
> Right.  Something like this is what I looking for, but unable to find
> (it was late at night and my googling skills may not have been at the
> top of their game...:-) )
>
> > 4. If you really have to, you can blacklist a bundle using the karaf
> maven
> > plugin, but that would be a last resort IMHO.
>
> Hm... this sounds like the kind of thing that made OSGi messy before I
> discovered karaf and features in 2016.  So I agree.
>
> > I would use one of the first 2 options primarily.  Also, you can use the
> > maven exclude to prevent certain transitives from being added to the
> > feature xml.
>
> I run with
>    <includeTransitiveDependency>false</includeTransitiveDependency>
> by default.
>
> Thanks for your help so far! :-)
>
>

Re: How to make karaf-maven-plugin exclude some compile depencies when building a feature?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Ryan Moquin <fr...@gmail.com>:

> Hi Steinar,
> There are a couple ways.

> 1. You can use <scope>runtime</scope> to prevent a jar from being added,
> but that has other ramifications when building (such as I think unit test
> code won't see the dependency)
> 2. You can use <scope>provided</scope> to only include that dependency but
> not of it's transitive dependencies in the feature.xml

Yup, but I didn't want to touch their dependencies if I could avoid it.

> 3. The karaf maven plugin has an option to excludeArtifactId (look in the
> docs of the karaf site)

Right.  Something like this is what I looking for, but unable to find
(it was late at night and my googling skills may not have been at the
top of their game...:-) )

> 4. If you really have to, you can blacklist a bundle using the karaf maven
> plugin, but that would be a last resort IMHO.

Hm... this sounds like the kind of thing that made OSGi messy before I
discovered karaf and features in 2016.  So I agree.

> I would use one of the first 2 options primarily.  Also, you can use the
> maven exclude to prevent certain transitives from being added to the
> feature xml.

I run with
   <includeTransitiveDependency>false</includeTransitiveDependency>
by default.

Thanks for your help so far! :-)


Re: How to make karaf-maven-plugin exclude some compile depencies when building a feature?

Posted by Ryan Moquin <fr...@gmail.com>.
Hi Steinar,

There are a couple ways.

1. You can use <scope>runtime</scope> to prevent a jar from being added,
but that has other ramifications when building (such as I think unit test
code won't see the dependency)
2. You can use <scope>provided</scope> to only include that dependency but
not of it's transitive dependencies in the feature.xml
3. The karaf maven plugin has an option to excludeArtifactId (look in the
docs of the karaf site)
4. If you really have to, you can blacklist a bundle using the karaf maven
plugin, but that would be a last resort IMHO.

I would use one of the first 2 options primarily.  Also, you can use the
maven exclude to prevent certain transitives from being added to the
feature xml.

Hope that helps,
Ryan

On Fri, Aug 30, 2019 at 6:51 PM Steinar Bang <sb...@dod.no> wrote:

> Is it possible to make karaf-maven-plugin exclude some dependencies with
> <scope>compile</scope>?
>
> I'm trying to create a pull request to fix this issue
>  https://github.com/pgjdbc/pgjdbc/issues/1552
> and the PostgreSQL JDBC driver pulls in and includes two dependencies,
> that I would like to not pull in with the feature.
>
> Firstly, the aren't needed (since they are embedded into the psql jar).
> Secondly, they aren't OSGi bundles, so karaf wraps them:
> 51 │ Active │  80 │ 0               │
> wrap_file__home_sb_.m2_repository_com_github_waffle_waffle-jna_1.9.1_waffle-jna-1.9.1.jar
> 52 │ Active │  80 │ 0               │
> wrap_file__home_sb_.m2_repository_com_ongres_scram_client_2.0_client-2.0.jar
>
> Thanks!
>
>

Re: PostgreSQL JDBC driver karaf feature repository file has problems building on RH EL7

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> My PR adding the creation of a karaf feature repository file and
> attaching the feature repository to the JDBC driver, has problems in
> the JDBC driver team's RH EL7 build:
>  https://github.com/pgjdbc/pgjdbc/pull/1554#issuecomment-535722657
>  https://github.com/pgjdbc/pgjdbc/pull/1554#issuecomment-536174617

Note: The RH EL7 build has been fixed, so there is no need to look
further into this:
 https://github.com/pgjdbc/pgjdbc/pull/1554#issuecomment-537079192


PostgreSQL JDBC driver karaf feature repository file has problems building on RH EL7

Posted by Steinar Bang <sb...@dod.no>.
My PR adding the creation of a karaf feature repository file and
attaching the feature repository to the JDBC driver, has problems in
the JDBC driver team's RH EL7 build:
 https://github.com/pgjdbc/pgjdbc/pull/1554#issuecomment-535722657
 https://github.com/pgjdbc/pgjdbc/pull/1554#issuecomment-536174617

Does anyone see what the problem is?

(I have googled NoSuchElementException and karaf but haven't found
anything obvious).

Here are version numbers of maven and java (kind of old maven, but an as
recent as possible java 8) from the build machine and a stack trace from
the maven build failure:

mvn --version
Apache Maven 3.0.5 (Red Hat 3.0.5-17)
Maven home: /usr/share/maven
Java version: 1.8.0_222, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.21.1.el7.x86_64", arch: "amd64", family: "unix"

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.2.5:features-generate-descriptor (generate-features-file) on project postgresql: Unable to create features.xml file: org.apache.maven.plugin.MojoExecutionException: java.util.NoSuchElementException
role: org.eclipse.aether.RepositorySystem
roleHint:
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to create features.xml file: org.apache.maven.plugin.MojoExecutionException: java.util.NoSuchElementException
role: org.eclipse.aether.RepositorySystem
roleHint:
at org.apache.karaf.tooling.features.GenerateDescriptorMojo.execute(GenerateDescriptorMojo.java:364)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: org.apache.maven.plugin.MojoExecutionException: java.util.NoSuchElementException
role: org.eclipse.aether.RepositorySystem
roleHint:
at org.apache.karaf.tooling.utils.DependencyHelperFactory.createDependencyHelper(DependencyHelperFactory.java:63)
at org.apache.karaf.tooling.features.GenerateDescriptorMojo.execute(GenerateDescriptorMojo.java:346)
... 21 more
Caused by: org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
role: org.eclipse.aether.RepositorySystem
roleHint:
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:257)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:245)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:239)
at org.apache.karaf.tooling.utils.DependencyHelperFactory.createDependencyHelper(DependencyHelperFactory.java:58)
... 22 more
Caused by: java.util.NoSuchElementException
at org.sonatype.guice.plexus.locators.RealmFilter$FilteredItr.next(RealmFilter.java:96)
at org.sonatype.guice.plexus.locators.RealmFilter$FilteredItr.next(RealmFilter.java:54)
at org.sonatype.guice.plexus.locators.DefaultPlexusBeans$Itr.next(DefaultPlexusBeans.java:60)
at org.sonatype.guice.plexus.locators.DefaultPlexusBeans$Itr.next(DefaultPlexusBeans.java:48)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:253)
... 25 more


Re: ANN: PostgreSQL JDBC driver 4.2.8 has a karaf feature attached

Posted by Francois Papon <fr...@openobject.fr>.
Thanks Steinar!

regards,

François
fpapon@apache.org

Le 26/09/2019 à 23:11, Steinar Bang a écrit :
> (Not really my news to announce, but I'm doing it anyway...:-) )
>
> The current version of the PostgreSQL JDBC driver, ie. 4.2.8, comes with
> a karaf feature repository file attached.  The karaf feature repository
> file has been present since version 4.2.7 of the driver:
>  https://jdbc.postgresql.org/documentation/changelog.html#version_42.2.7
>
> Copy/pastable code for usage with template feature file:
>  1. In pom.xml:
>     <properties>
>         <postgresql.version>42.2.8</postgresql.version>
>     </properties>
>
>  2. In src/main/feature/feature.xml (ie. the template feature file):
>      <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="authservice.bundle">
>          <repository>mvn:org.postgresql/postgresql/${postgresql.version}/xml/features</repository>
>          <feature name="${karaf-feature-name}">
>              <feature>postgresql</feature>
>              <feature>scr</feature>
>          </feature>
>      </features>
>
> Copy/pastable code for usage with a feature file dependency:
>  1. In pom.xml:
>     <properties>
>         <postgresql.version>42.2.8</postgresql.version>
>     </properties>
>
>     <dependencies>
>         <dependency>
>             <groupId>org.postgresql</groupId>
>             <artifactId>postgresql</artifactId>
>             <version>${postgresql.version}</version>
>             <scope>provided</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.postgresql</groupId>
>             <artifactId>postgresql</artifactId>
>             <version>${postgresql.version}</version>
>             <type>xml</type>
>             <classifier>features</classifier>
>         </dependency>
>     </dependencies>
>

ANN: PostgreSQL JDBC driver 4.2.8 has a karaf feature attached

Posted by Steinar Bang <sb...@dod.no>.
(Not really my news to announce, but I'm doing it anyway...:-) )

The current version of the PostgreSQL JDBC driver, ie. 4.2.8, comes with
a karaf feature repository file attached.  The karaf feature repository
file has been present since version 4.2.7 of the driver:
 https://jdbc.postgresql.org/documentation/changelog.html#version_42.2.7

Copy/pastable code for usage with template feature file:
 1. In pom.xml:
    <properties>
        <postgresql.version>42.2.8</postgresql.version>
    </properties>

 2. In src/main/feature/feature.xml (ie. the template feature file):
     <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="authservice.bundle">
         <repository>mvn:org.postgresql/postgresql/${postgresql.version}/xml/features</repository>
         <feature name="${karaf-feature-name}">
             <feature>postgresql</feature>
             <feature>scr</feature>
         </feature>
     </features>

Copy/pastable code for usage with a feature file dependency:
 1. In pom.xml:
    <properties>
        <postgresql.version>42.2.8</postgresql.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
            <type>xml</type>
            <classifier>features</classifier>
        </dependency>
    </dependencies>


PostgreSQL JDBC driver now has a karaf feature attached (Was: How to make karaf-maven-plugin exclude some compile depencies when building a feature?)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> The PR is here if anyone would like to take a look at it:
>  https://github.com/pgjdbc/pgjdbc/pull/1554

The PR was merged to pgjdbc master, so when the next release of pgjdbc is done, it should be possible to use the attached feature:

1. From a maven dependency in a maven module building and attaching its own feature file:
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.2.7</version>
        <type>xml</type>
        <classifier>features</classifier>
    </dependency>

2. Alternatively, using a template feature.xml file:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="authservice.bundle">
        <repository>mvn:org.postgresql/postgresql/42.2.7/xml/features</repository>
            <feature name="${karaf-feature-name}">
            <feature>postgresql</feature>
        </feature>
    </features>

(I'm guessing at the version name for the next pgjdbc release, it's the current SNAPSHOT without -SNAPSHOT)


Re: How to make karaf-maven-plugin exclude some compile depencies when building a feature?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:

> you can blacklist or you can exclude artifacts.

Right.  I tried using blacklisting in the karaf-maven-plugin
documentation, but that didn't work as I expected it to.

I looked for something like the exclusion of artifacts in the
karaf-maven-plugin documentation, but as I said in the reply to Ryan,
couldn't find it.

(If you're thinking of exclusion in the dependencies, that wasn't easy
to do because of dependency inheritance and use profiles and the
dependencies were used to include the problem packages into the jar
(maybe... it was hard to tell))

> You can also use a different scope than compile,

Yes, but I didn't want to mess with their dependencies (especially since
the maven config was so complicated).

> or use a features.xml "template".

Yep, I already do that.  But all non-transitive compile scope
dependencies are pulled in.

Thanks for your help!

The PR is here if anyone would like to take a look at it:
 https://github.com/pgjdbc/pgjdbc/pull/1554

For now I let the two wrap'ed jar files stay.  I have tested replacing
my own hand-written PostgreSQL karaf feature[1] with he piggy backed
feature, and the feature created by the pull request works fine.

References:
[1] <https://github.com/steinarb/postgresql-jdbc-karaf-feature>


Re: How to make karaf-maven-plugin exclude some compile depencies when building a feature?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

you can blacklist or you can exclude artifacts.

You can also use a different scope than compile, or use a features.xml
"template".

Regards
JB

On 31/08/2019 00:52, Steinar Bang wrote:
> Is it possible to make karaf-maven-plugin exclude some dependencies with
> <scope>compile</scope>?
> 
> I'm trying to create a pull request to fix this issue
>  https://github.com/pgjdbc/pgjdbc/issues/1552
> and the PostgreSQL JDBC driver pulls in and includes two dependencies,
> that I would like to not pull in with the feature.
> 
> Firstly, the aren't needed (since they are embedded into the psql jar).
> Secondly, they aren't OSGi bundles, so karaf wraps them:
> 51 │ Active │  80 │ 0               │ wrap_file__home_sb_.m2_repository_com_github_waffle_waffle-jna_1.9.1_waffle-jna-1.9.1.jar
> 52 │ Active │  80 │ 0               │ wrap_file__home_sb_.m2_repository_com_ongres_scram_client_2.0_client-2.0.jar
> 
> Thanks!
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com