trustin / os-maven-plugin

A Maven plugin that sets various useful properties detected from ${os.name} and ${os.arch} properties.
Apache License 2.0
295 stars 66 forks source link

Prefix os.detected.classifier property on mac #20

Open jkirsch opened 8 years ago

jkirsch commented 8 years ago

This is a small feature request.

Currently the plugin does not work out of the box with the bytedeco/javacpp-presets on mac.

For example, the opencv bindings are published for different architectures

http://search.maven.org/#search%7Cga%7C1%7Corg.bytedeco.javacpp-presets%20opencv

MacOs is refered to as macosx-x86_64, whereas currently the plugin resolves mac to osx.

Is there some way to overwrite the detection, such that no additional handling of this case is needed and one can simply write

<dependency>
   <groupId>org.bytedeco.javacpp-presets</groupId>
   <artifactId>opencv</artifactId>
   <classifier>${os.detected.classifier}</classifier>
</dependency>
trustin commented 8 years ago

Sounds like a good idea. Will try to find some time.

bin01 commented 7 years ago

@trustin I am currently running into a similar issue. Is there any known workaround for this issue?

taftster commented 7 years ago

Be careful here. Other projects have used the value of 'osx' instead of 'macosx' when publishing classifiers to maven central. Google's protoc for example uses the 'osx' classifier. This will need a configuration property or something for backwards compatibility.

RobertoUa commented 5 years ago

any news?

trustin commented 3 years ago

What do you think about letting a user create a file (.os-mappings.json in project root) that contains something like this:

{
  "copiedProperties": [
    {
      "src": "os.detected.name",
      "dest": "os.detected.name.alternative",
      "replacements": {
        "osx": "macos"
      }
    },
    {
      "src": "os.detected.arch",
      "dest": "os.detected.arch", // overwrite
      "replacements": {
        "s390_32": "s390",
        "s390_64": "s390x"
      }
    }
  ],
  "additionalProperties": {
    "os.detected.classifier.alternative": "${os.detected.name.alternative}-${os.detected.arch}",
    "myCustomProp": "foobar"
  }
}

Then, a user could use ${os.detected.classifier.alternative} for the dependencies with a macos-* classifier.

taftster commented 3 years ago

Would this custom mappings file allow a developer to pull dependencies from classifiers that were BOTH 'osx' and 'macosx' in their pom? I think that's the minimum requirement. Something like this should be possible:

<!-- uses original 'osx' value -->
<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protoc</artifactId>
  <classifier>${os.detected.classifier}</classifier>
</dependency>

<!-- uses alternative 'macosx' value -->
<dependency>
  <groupId>org.bytedeco.javacpp-presets</groupId>
  <artifactId>opencv</artifactId>  
  <classifier>${os.detected.classifier.alternative}</classifier>
</dependency>

For extra credit, hypothetically what if there were three or more distinct values for classifier? Can this solution produce those variants? Maybe we need something like: ${os.detected.classifier.alternative.1} and ${os.detected.classifier.alternative.2} etc.?

trustin commented 3 years ago

Would this custom mappings file allow a developer to pull dependencies from classifiers that were BOTH 'osx' and 'macosx' in their pom? I think that's the minimum requirement.

Yeah, that's what the example .json file tries to show.

For extra credit, hypothetically what if there were three or more distinct values for classifier?

Yeah, something like this:

{
  "copiedProperties": [
    {
      "src": "os.detected.name",
      "dest": "os.detected.name.alternative.1",
      "replacements": {
        "osx": "macos"
      }
    },
    {
      "src": "os.detected.name",
      "dest": "os.detected.name.alternative.2",
      "replacements": {
        "osx": "apple"
      }
    }
  ]
}
taftster commented 3 years ago

Perfect. Seems like a really nice solution then! +1 Thanks for the explanation.

juzi214032 commented 2 years ago

any news?

vin188 commented 2 years ago

What do you think about letting a user create a file (.os-mappings.json in project root) that contains something like this:

{
  "copiedProperties": [
    {
      "src": "os.detected.name",
      "dest": "os.detected.name.alternative",
      "replacements": {
        "osx": "macos"
      }
    },
    {
      "src": "os.detected.arch",
      "dest": "os.detected.arch", // overwrite
      "replacements": {
        "s390_32": "s390",
        "s390_64": "s390x"
      }
    }
  ],
  "additionalProperties": {
    "os.detected.classifier.alternative": "${os.detected.name.alternative}-${os.detected.arch}",
    "myCustomProp": "foobar"
  }
}

Then, a user could use ${os.detected.classifier.alternative} for the dependencies with a macos-* classifier.

I create .os-mappings.json in project root, but it's doesn't work