Well,
Package version numbers are present to identify differences between the specification and the implementation, i.e. bugs.
http://docs.oracle.com/javase/7/docs/technotes/guides/versioning/spec/versioning2.html
Assuming a vendor has a spec- and a impl- version offered.
Questions:
Maven and Java- Spec/Impl versions are slightly different concepts. They can be made to work with each other, however, it takes some effort.
Maven's multi-module approach encourages splitting modules into api (or spec) and implementation modules. So, to use the java versions, you would have to:
Look at the following example (I have ommited some best practices such as dependencyManagement for brevity's sake:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blackbuild.maven.demo.specimpl</groupId>
<artifactId>module-spec</artifactId>
<version>1.0</version>
<name>Module Demo Specification</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<!-- This is an API project, use only specification entries -->
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Manifest-Version: 1.0
Built-By: xxx
Build-Jdk: 1.6.0_27
Specification-Title: Module Demo Specification
Created-By: Apache Maven 3.0.5
Specification-Version: 1.0
Archiver-Version: Plexus Archiver
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blackbuild.maven.demo.specimpl</groupId>
<artifactId>module-impl</artifactId>
<version>1.5-SNAPSHOT</version>
<name>Module Demo Implementation</name>
<properties>
<!-- Define specification coordinates -->
<spec-title>Module Demo Specification</spec-title>
<spec-vendor>Spec Provider</spec-vendor>
<spec-version>1.0</spec-version>
</properties>
<dependencies>
<dependency>
<groupId>com.blackbuild.maven.demo.specimpl</groupId>
<artifactId>module-spec</artifactId>
<version>${spec-version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Specification-Title>${spec-title}</Specification-Title>
<Specification-Version>${spec-version}</Specification-Version>
<Specification-Vendor>${spec-vendor}</Specification-Vendor>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Manifest-Version: 1.0
Implementation-Title: Module Demo Implementation
Implementation-Version: 1.5-SNAPSHOT
Implementation-Vendor-Id: com.blackbuild.maven.demo.specimpl
Built-By: xxx
Build-Jdk: 1.6.0_27
Specification-Vendor: Spec Provider
Specification-Title: Module Demo Specification
Created-By: Apache Maven 3.0.5
Specification-Version: 1.0
Archiver-Version: Plexus Archiver
Of course, you have to release both modules individually.
Back to your questions:
With this model, you can have different implementations for the same specification, as long as they have different coordinates themselves (different versions, usually).
Maven uses a single coordinate pre artifact, spec version is implemented by using dependencies. In normal workflow, you are either interested in spec version or in the implementation version, but rarely in both at the same time. You can assure that the implementation matches the specification by using dependencyManagement and enforcer rules, if necessary
No, I think the api/impl model of Maven is more widely used.
In this model, there is no way to read the specification version from the implementation (without looking into the Manifest).
You could use a {spec-version}_{impl-version} versioning scheme to resolve this, for the above example, impl-version could be 1.5_1.0.0-SNAPSHOT, however this makes version numbers much harder to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With