You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mark Raynsford <or...@io7m.com> on 2018/05/18 11:25:35 UTC

Accessing licenses/license as POM properties?

Hello.

Is there a way to access the contents of the <licenses> element as POM
properties? I'd like to reference the URL of the first license element
in a plugin execution, but there doesn't appear to be a
${pom.license.url} or anything similar.

-- 
Mark Raynsford | http://www.io7m.com


Re: Accessing licenses/license as POM properties?

Posted by Mark Raynsford <or...@io7m.com>.
This seems to be a bug or something not quite right with the
bnd-maven-plugin. I've filed an issue:
https://github.com/bndtools/bnd/issues/2454

Plugins like the maven-jar-plugin (and evidently the
maven-bundle-plugin) appear to do the right thing, but the
bnd-maven-plugin seems not to. Strangely, other expressions (like
${project.description}) are expanded properly, but more complex
expressions aren't.

-- 
Mark Raynsford | http://www.io7m.com


Re: Accessing licenses/license as POM properties?

Posted by Mark Raynsford <or...@io7m.com>.
On 2018-05-19T14:35:25 +0200
Andreas Sewe <se...@st.informatik.tu-darmstadt.de> wrote:
>
> Maybe it depends on the Maven version (here: 3.5.2)? Try to clone the
> above Github repository, do a "mvn clean verify" and check what "unzip
> -p
> bundles/com.ctrlflow.aer.client.dto/target/com.ctrlflow.aer.client.dto-2.0.2-SNAPSHOT.jar
> META-INF/MANIFEST.MF" outputs for you.

I'm on 3.5.2:

Apache Maven 3.5.2 (NON-CANONICAL_2017-10-25T13:09:52+03:00_root; 2017-10-25T11:09:52+01:00)
Maven home: /opt/maven
Java version: 10.0.1, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-10-openjdk
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.16.4-1-arch", arch: "amd64", family: "unix"

Your bundles have the correct manifest entries on my system:

  Bundle-License: https://www.eclipse.org/legal/epl-v10.html;description
 ="Eclipse Public License"

> Also, check what "mvn help:effective-pom" produces on your project vs.
> my project.

The effective POM for my project shows the unexpanded
${project.licenses[0]} text.

I feel like I might be running into a bug here... Going to attempt to
produce a repro case and submit an issue to the tracker.

-- 
Mark Raynsford | http://www.io7m.com


Re: Accessing licenses/license as POM properties?

Posted by Andreas Sewe <se...@st.informatik.tu-darmstadt.de>.
Mark Raynsford wrote:
> Spoke a bit too soon. I'm using the bnd-maven-plugin, but I don't think
> that changes anything. I have:
> 
>         <plugin>
>           <groupId>biz.aQute.bnd</groupId>
>           <artifactId>bnd-maven-plugin</artifactId>
>           <version>${io7m.bnd-maven-plugin.version}</version>
>           <configuration>
>             <bnd><![CDATA[
>               Bundle-Description: ${project.description}
>               Bundle-License: ${project.licenses[0].name}
> ]]></bnd>
>           </configuration>
>         </plugin>
> 
> Unfortunately, the resulting bundle manifest is:
> 
>   Bundle-Description  Contract checking      
>   Bundle-License      ${project.licenses[0].name}              
> 
> It seems that the array reference isn't being expanded. If I specify
> ${project.licenses}, I instead get:
> 
>   Bundle-License      [org.apache.maven.model.License@3eba57a7]
> 
> ... which is clearly the result of calling toString() on something
> that hasn't overridden it. Point is that the project.licenses property
> is definitely present, it's just that I'm unable to access any of the
> elements.

That is odd. I just rebuild my project [1] again and checked
MANIFEST.MF, as included in the JAR, and everything is as it should be:

> Bundle-License: https://www.eclipse.org/legal/epl-v10.html;description
>  ="Eclipse Public License"

Maybe it depends on the Maven version (here: 3.5.2)? Try to clone the
above Github repository, do a "mvn clean verify" and check what "unzip
-p
bundles/com.ctrlflow.aer.client.dto/target/com.ctrlflow.aer.client.dto-2.0.2-SNAPSHOT.jar
META-INF/MANIFEST.MF" outputs for you.

Also, check what "mvn help:effective-pom" produces on your project vs.
my project.

Hope this helps to diagnose the issue.

Best wishes,

Andreas

[1] <https://github.com/codetrails/ctrlflow-aer-client>


Re: Accessing licenses/license as POM properties?

Posted by Mark Raynsford <or...@io7m.com>.
On 2018-05-18T16:50:56 +0100
org.apache.maven.user@io7m.com wrote:

> On 2018-05-18T17:01:52 +0200
> Andreas Sewe <se...@st.informatik.tu-darmstadt.de> wrote:
>
> > here's what I use as an <instruction> for the maven-bundle-plugin to
> > generate a Bundle-License line in my MANIFEST.MF:
> >   
> > > <Bundle-License>${project.licenses[0].url};description="${project.licenses[0].name}"</Bundle-License>    
> > 
> > Works like a charm, as long as you have exactly one license.  
> 
> Looks good, thanks!
> 
> You're also using it for the exact same reason I'd be using it. :)

Spoke a bit too soon. I'm using the bnd-maven-plugin, but I don't think
that changes anything. I have:

        <plugin>
          <groupId>biz.aQute.bnd</groupId>
          <artifactId>bnd-maven-plugin</artifactId>
          <version>${io7m.bnd-maven-plugin.version}</version>
          <configuration>
            <bnd><![CDATA[
              Bundle-Description: ${project.description}
              Bundle-License: ${project.licenses[0].name}
]]></bnd>
          </configuration>
        </plugin>

Unfortunately, the resulting bundle manifest is:

  Bundle-Description  Contract checking      
  Bundle-License      ${project.licenses[0].name}              

It seems that the array reference isn't being expanded. If I specify
${project.licenses}, I instead get:

  Bundle-License      [org.apache.maven.model.License@3eba57a7]

... which is clearly the result of calling toString() on something
that hasn't overridden it. Point is that the project.licenses property
is definitely present, it's just that I'm unable to access any of the
elements.

--
Mark Raynsford | http://www.io7m.com


Re: Accessing licenses/license as POM properties?

Posted by or...@io7m.com.
On 2018-05-18T17:01:52 +0200
Andreas Sewe <se...@st.informatik.tu-darmstadt.de> wrote:

> Hi,
> 
> > Is there a way to access the contents of the <licenses> element as POM
> > properties? I'd like to reference the URL of the first license element
> > in a plugin execution, but there doesn't appear to be a
> > ${pom.license.url} or anything similar.  
> 
> here's what I use as an <instruction> for the maven-bundle-plugin to
> generate a Bundle-License line in my MANIFEST.MF:
> 
> > <Bundle-License>${project.licenses[0].url};description="${project.licenses[0].name}"</Bundle-License>  
> 
> Works like a charm, as long as you have exactly one license.

Looks good, thanks!

You're also using it for the exact same reason I'd be using it. :)

-- 
Mark Raynsford | http://www.io7m.com


Re: Accessing licenses/license as POM properties?

Posted by Andreas Sewe <se...@st.informatik.tu-darmstadt.de>.
Hi,

> Is there a way to access the contents of the <licenses> element as POM
> properties? I'd like to reference the URL of the first license element
> in a plugin execution, but there doesn't appear to be a
> ${pom.license.url} or anything similar.

here's what I use as an <instruction> for the maven-bundle-plugin to
generate a Bundle-License line in my MANIFEST.MF:

> <Bundle-License>${project.licenses[0].url};description="${project.licenses[0].name}"</Bundle-License>

Works like a charm, as long as you have exactly one license.

Hope this helps.

Andreas