aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.65k stars 245 forks source link

Expected behavior for * dependencies when compiling into Java #1678

Closed campionfellin closed 4 years ago

campionfellin commented 4 years ago

:question: Guidance

Affected Languages

General Information

The Question

What is the expected behavior when compiling * dependencies into Java? Here's part of an example package.json:

 jsii: {
      outdir: "dist",
      targets: {
        java: {
          package: "main",
          maven: {
            groupId: "main",
            artifactId: "main"
          }
        }
      }
    },    
    dependencies: {
      "constructs": "*",
      "cdk8s": "*",
    },

This leads to my dependencies in pom.xml looking like:

  <dependency>
      <groupId>org.cdk8s</groupId>
      <artifactId>cdk8s</artifactId>
      <version>[undefined]</version>
    </dependency>
    <dependency>
      <groupId>software.constructs</groupId>
      <artifactId>constructs</artifactId>
      <version>[undefined]</version>
    </dependency>

Changing versions from * to a numbered version like 2.0.1 or 0.21.0 seems to fix the issue.

Is this expected? Any solutions besides explicitly adding the version?

RomainMuller commented 4 years ago

How'd you model such a dependency in pom.xml?

The reason I as is because I see two ways of addressing this:

  1. Generate a valid pom.xml from this configuration (probably also for other languages)
  2. Prohibit * dependencies

I'd instinctively lean towards option 2, however I also don't like being more restrictive than needed (so if I can express * in other languages, I don't see why I'd refrain from doing it).

Generally speaking however, jsii packages are expected to adhere to semantic versioning, and having a * dependency would mean you're accepting any major version (including incompatible ones) - that doesn't sound like something you'd want to be doing?

campionfellin commented 4 years ago

I think for (1), something like this could be acceptable for maven/Java at least:

    <dependency>
      <groupId>org.cdk8s</groupId>
      <artifactId>cdk8s</artifactId>
      <version>(0.0.0,]</version>
    </dependency>

Alternatively, for (1), it looks like there are some plugins that could help (see here) but I'm not sure that's any better than just <version>(0.0.0,]</version>

(2) is also fine with me, if it can be added to the documentation somewhere!

campionfellin commented 4 years ago

@RomainMuller either option is fine with me, but I'd prefer (1). I can work on this if you'd like

RomainMuller commented 4 years ago

I'm happy with option (1), however as I mentioned on the PR (thanks for that by the way), I feel 0.0.0 should be included.

SomayaB commented 4 years ago

Closing this issue since it seems to have been resolved. Feel free to reopen.