guymahieu / ivyidea

Resolve dependencies for your Intellij projects using Ivy
Apache License 2.0
13 stars 18 forks source link

Support jpms/jigsaw module path #180

Open jbeckers opened 3 weeks ago

jbeckers commented 3 weeks ago

I'm trying to use Ivy/IvyIDEA to build a jpms module path.

(In my case to get Nashorn on the module path, e.g. https://github.com/szegedi/nashorn/wiki/Using-Nashorn-with-different-Java-versions#using-nashorn-on-java-11-to-14)

I think Ivy has everything I need to do this. I'm not so sure about IntelliJ and IvyIDEA.

In ivy.xml, I'll to model this by changing the type of the artifact to "mod" instead of "jar"

    <publications>
        <artifact name="nashorn-core" type="mod" ext="jar" conf="java11plus"/>
        <artifact name="nashorn-core" type="source" ext="jar" uz:classifier="sources" conf="java11plus"/>
    </publications>

Then in our ant build scripts, I'll do two resolves:

        <ivy:cachepath pathId="app.java11plus.classpath"
                       file="${ivy.file}"
                       conf="${configs.to.resolve}"
                       type="jar"
                       log="quiet"
                       transitive="true"
                       resolveId="app.java11plus.classpath.resolveId"/>
        <ivy:cachepath pathId="app.java11plus.modulepath"
                       file="${ivy.file}"
                       conf="${configs.to.resolve}"
                       type="mod"
                       log="quiet"
                       transitive="true"
                       resolveId="app.java11plus.modulepath.resolveId"/>

So far, so good, I think? This should work for ant. But what about IntelliJ? IvyIDEA probably needs some work to support this.

At first guess:

1/ add a category "JPMS Modules" to the IvyIDEA settings: afbeelding

2/ when resolving, create (an) extra module librar(y/ies) that only contains the jpms modules? Questions: does the intellij project model support this? Do we need an extra library per configuration?

3/ when running, add these libraries to the module path somehow?

I'm willing to do some work on this, but I thought I'd ask if any work has been done already before starting.

jbeckers commented 3 weeks ago

Or 2/ when resolving, add the jpms modules to the module libraries in a new category. Questions: does the intellij project model support this?

maartenc commented 3 weeks ago

I'm not sure this is necessary? It seems that IntelliJ has some smart logic to put the dependencies in the correct module/class path: https://youtrack.jetbrains.com/issue/IDEA-171320/Set-module-path-and-class-path

On compilation of a module with module-info, IDEA would put all (transitively) required dependencies specified in module-info on the module path, everything else would be left on the class path, similarly how it's done in maven

guymahieu commented 3 weeks ago

Not sure about this, but wouldn't you need to add the "mod" artifact type to the "Classes" category in the settings (see your screenshot)?

jbeckers commented 3 weeks ago

Ok, I'm starting to make sense of this, but I'm not liking what I find. 😆

Reading the youtrack and others, it seems like I needn't change a thing in ivy. The result of ivy resolve gives me a set of jars (old-style and/or jpms) and deciding which of those to actually put on the module path needs to be done based on module-info.

I was hoping to avoid putting module-info in the module that needs nashorn, since this turns the module into a jpms module (right?) and we're not ready for that.

If IntelliJ provides no other options to add mods to the module path (apart from manually specifying the --module-path in the run configuration), I seem to be stuck.

I'm still wondering whether the JRE/JPMS itself will force me to add module-info. Not easy to get my head around.

Let me try some things and get back in a few days.