OrienteerBAP / JNPM

Native Java API to work with JavaScript Node Package Manager (NPM): query, retrieve, pack into jar (webjars), CDN
Apache License 2.0
20 stars 1 forks source link

Java artifact publication to central #5

Closed sansp00 closed 3 years ago

sansp00 commented 3 years ago

Would it be possible to add the publication to maven central or bintray of the different java artifacts (maven plugin and libs) ? I cannot seem to find any of the artifacts on the repos mentionned above. Thank you

PhantomYdn commented 3 years ago

Thank you for letting me know. It seems that the release for some reasons was not propagated to central and published... In meanwhile, I recommend using the following inclusions in your pom.xml

For jnpm-maven-plugin:

<pluginRepositories>
    <pluginRepository>
        <id>ossrh.plugins</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </pluginRepository>
</pluginRepositories>

For JMPM as dependency in java:

<repositories>
    <repository>
        <id>snapshots-repo</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

And use 1.1-SNAPSHOT. For example:

<plugin>
    <groupId>org.orienteer.jnpm</groupId>
    <artifactId>jnpm-maven-plugin</artifactId>
    <version>1.1-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>install</goal>
            </goals>
            <configuration>
                <packages>
                    <package>vue@2.6.11</package>
                    <package>http-vue-loader@1.4.2</package>
                </packages>
                <pathPrefix>org/orienteer/vuecket/external</pathPrefix>
                <strategy>SIMPLE</strategy>
            </configuration>
        </execution>
    </executions>
</plugin>

or:

<dependency>
        <groupId>org.orienteer.jnpm</groupId>
        <artifactId>jnpm</artifactId>
        <version>1.1-SNAPSHOT</version>
</dependency>
sansp00 commented 3 years ago

Thanks for such a quick reply ! The semver librairy seems to be causing problems ...

[ERROR] Failed to execute goal org.orienteer.jnpm:jnpm-maven-plugin:1.1-SNAPSHOT:install (default) on project test-app: Execution default of goal org.orienteer.jnpm:jnpm-maven-plugin:1.1-SNAPSHOT:install failed: Plugin org.orienteer.jnpm:jnpm-maven-plugin:1.1-SNAPSHOT or one of its dependencies could not be resolved: Failed to collect dependencies at org.orienteer.jnpm:jnpm-maven-plugin:jar:1.1-20200801.085225-2 -> org.orienteer.jnpm:jnpm:jar:1.1-SNAPSHOT -> com.github.zafarkhaja:java-semver:jar:0.10.0: Failed to read artifact descriptor for com.github.zafarkhaja:java-semver:jar:0.10.0: Could not transfer artifact com.github.zafarkhaja:java-semver:pom:0.10.0 from/to heisluft-repo (https://heisluft.tk/maven/): Transfer failed for https://heisluft.tk/maven/com/github/zafarkhaja/java-semver/0.10.0/java-semver-0.10.0.pom ProxyInfo{host='127.0.0.1', userName='null', port=9000, type='http', nonProxyHosts='null'}: heisluft.tk:443 failed to respond -> [Help 1]

Building from source fails in a similar fashion

It seems that the repo hosting the lib https://heisluft.tk/maven/ does not 'exists' anymore :(

PhantomYdn commented 3 years ago

That's sad... Trying to retarget to original library. Seems that the returned back - so should work. https://github.com/zafarkhaja/jsemver/issues/56 Please give me some time.

sansp00 commented 3 years ago

On a side note, the lib com.github.zafarkhaja:java-semver does not seem to be maintained anymore (6+ years without updates). Moving to Semver4j or similar maintained lib would ease that pain.

PhantomYdn commented 3 years ago

Yea - that's why I used forked version. This one: https://github.com/zafarkhaja/jsemver/issues/56 And this version was located in that custom MVN repository.

PhantomYdn commented 3 years ago

@sansp00 , I just pushed migration to Semver4j under #6 . Please let me know if you have any problems. Not sure that republishing version 1.0 makes sense - because people will not have access to jsemver dependency.

sansp00 commented 3 years ago

Could it be published under a version fix or feature (1.0.1 or 1.1) ? Having your latest enhancements and an official artifact in Central/Bintray would really be helpful for me.

PhantomYdn commented 3 years ago

OK. Will figure out why v1.0 was not published before and will push update under v1.1. Will let you know once it will be done.

PhantomYdn commented 3 years ago

Figured out the problem: https://github.com/OrienteerBAP/JNPM/commit/eed2bba25f837c36bca266e5b47eb07ee75b9af4 Just pushed version 1.1 to the maven, but it might take several hours for propagation to maven central.

I'm really interested in how are you going to use the library. Please share a few words.

sansp00 commented 3 years ago

Perfect, I will look into it tomorrow. Thank you for all the work, it is really appreciated. I'm experimenting with the plugin in order to have simpler approach for our builds. The end goal is to produce a web archive with the npm stuff in it using Maven, but due to the way our CI and pipelines are setup, we are unable to easily bridge/combine a NPM workload with Maven. So the idea is to have a pipeline handling a vanilla NPM workload and having another in which, with the help of the plugin to download the npm artifacts, will produce the required web archive (single responsability principle). The current approach requires the full stack tool chain when doing front-end development which is overkill and a PITA to deal with.

PhantomYdn commented 3 years ago

@sansp00, sounds very familiar:) If I get you correctly: you want to create a report with used packages in one pipeline and feed it to another one. In this case, I guess, will be helpful if JNMP maven plugin can take a list of packages from outside (not from pom.xml). Am I right? I can add this feature as well.

Btw, 1.1 version is already on maven central.

sansp00 commented 3 years ago

I've played quite a bit with the plugin this morning. Here is a rundown of my work session:

That being said, after messing with your latest code drop, I was able to poke our internal repository, but I was not able to dump the npm packages to my output directory. Due to time constraint, I did not have time to dig deeper to figure out the culprit.

This plugin shows lot of potential, since there is nothing in Maven, AFAIK, that does not delegate to an npm installation on the machine.

PhantomYdn commented 3 years ago

Thank you! Few questions/comments:

there is nothing in Maven, AFAIK, that does not delegate to an npm installation on the machine Yes - that's the main idea of JNPM: avoid NPM installations and do stuff purely in java.

sansp00 commented 3 years ago

Re,

I am using the Maven plugin exclusively.

PhantomYdn commented 3 years ago

I have reworked code:

Regarding your problem: by default JNPM put extracted packages to target/ directory (to be precise: target/jnpm/META-INF) - so there is no need to commit into git packages itself. But you can easily configure that through extra properties:

jnpm:install
  Goal to download, extract and attach npm resources

  Available parameters:

    attachResources (Default: true)
      Attach downloaded resources to the build process

    excludes
      What has to be excluded from resources to be attached

    getDev (Default: false)
      Download development dependencies

    getOptional (Default: false)
      Download optional dependencies

    getPeer (Default: false)
      Download peer dependencies

    getProd (Default: false)
      Download direct dependencies

    includes
      What should be included as resources (Default: empty - means everything)

    outputDirectory (Default: ${project.build.directory}/jnpm/)
      Location of the output directory
      Required: Yes

    packages
      NPM packages to be downloaded and extracted (For example: vue@2.6.11)
      Required: Yes

    password
      Password for authentication (optional)

    pathPrefix
      Prefix for the directory under outputDirectory to which files will be
      placed

    registryUrl (Default: http://registry.npmjs.org/)
      NPM registry URL to be used for package lookup and retrieval

    strategy (Default: WEBJARS)
      Installation strategy to be used

    username
      Username for authentication (optional)

Example of pom.xml which perfectly works for me:

<plugin>
    <groupId>org.orienteer.jnpm</groupId>
    <artifactId>jnpm-maven-plugin</artifactId>
    <version>1.2-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>install</goal>
            </goals>
            <configuration>
                <packages>
                    <package>a@2.1.2</package>
                    <package>b@2.0.1</package>
                </packages>
                <excludes>
                    <exclude>**/package.json</exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>   
</plugin>
PhantomYdn commented 3 years ago

Hello @sansp00 , do you have some updates after using recent updates?