Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module names for better Java 9/Jigsaw support #274

Merged
merged 2 commits into from
Mar 27, 2018

Conversation

lossyrob
Copy link
Member

@lossyrob lossyrob commented Mar 23, 2018

The Jigsaw module system requires that downstream users of JTS using the module system declare JTS as a module requirement. JTS acts as an automatic module, since it is not compiled with a module-info.java. Without this change, module users would have to reference the requirement for JTS by specifying the JAR name with the fully qualified version; this is unwieldy, will trigger necessary updates when updating the JTS version, and could cause errors when transitive dependencies rely on other versions of JTS.

This change utilizes the technique of putting the module name in the manifest, so that libraries declaring modules can refer to JTS with more friendly, version-less names, e.g.:

// module-info.java for project org.foo.baz

module org.foo.baz {
  requires org.locationtech.jts;            // jts-core
  requires org.locationtech.jts.io;         // jts-io-common
  requires org.locationtech.jts.io.oracle;  // jts-io-ora
  requires org.locationtech.jts.io.sde;     // jts-io-sde
}

Testing Instructions

To verify this work, I defined a Foo.java file and a manifest-info.java file, as follows:

// Foo.java

package org.foo.baz;

import org.locationtech.jts.JTSVersion;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.algorithm.distance.DistanceToPoint;
import org.locationtech.jts.io.geojson.GeoJsonConstants;

public class Foo {
  public static void main(String[] args)
  {
    ParseException e = new ParseException("asdf");
    DistanceToPoint d = new DistanceToPoint();
    System.out.println(JTSVersion.CURRENT_VERSION);
    System.out.println(GeoJsonConstants.NAME_GEOMETRIES);
  }
}
// module-info.java

module org.foo.baz {
  requires org.locationtech.jts;
  requires org.locationtech.jts.io;
}

I then compiled and ran Foo as a module:

> mkdir mods
> javac --module-path ./modules/core/target/jts-core-1.15.1-SNAPSHOT.jar:./modules/io/common/target/jts-io-common-1.15.1-SNAPSHOT.jar \
        -d mods/foo \
        module-info.java \
        Foo.java
> java --module-path mods:./modules/core/target/jts-core-1.15.1-SNAPSHOT.jar:./modules/io/common/target/jts-io-common-1.15.1-SNAPSHOT.jar -m org.foo.baz/org.foo.baz.Foo

Expected output:

1.15.0
geometries

This is building JTS with java 8 against commit 3fb74b6

…va 9

Signed-off-by: lossyrob <rdemanuele@gmail.com>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.locationtech.jts.io.orcale</Automatic-Module-Name>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Signed-off-by: lossyrob <rdemanuele@gmail.com>
@jodygarnett jodygarnett merged commit 181003a into locationtech:master Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants