lgrignon / jsweet-gradle-plugin

Brings the power of JSweet to Gradle
Apache License 2.0
17 stars 15 forks source link

Publish JSweet 3 artifacts to public repos #25

Closed Skillzore closed 3 years ago

Skillzore commented 3 years ago

Hi!

I am trying to add the jsweet-transpiler and only the transpiler to an existing react project that I have. I am hoping to use the transpiler to create typescript code from my java validation code and run that typescript code on the clientside.

What I have added to my build.gradle so far:

plugins {
        ....
    id "org.jsweet.jsweet-gradle-plugin" version "3.0.1"
    id 'java'
}

group = 'com.myapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
    maven { url "http://repository.jsweet.org/artifactory/libs-release-local" }
}

dependencies {
        ....
    compile group: 'org.jsweet', name: 'jsweet-transpiler', version: "3.0.0"
}

jsweet {
    verbose = true
    encoding = 'UTF-8'
    sourceMap = true
    outDir = project.file('target/javascript')
    candiesJsOut = project.file('target/candies')
    targetVersion = 'ES6'
    includes = ['**/fr/test/my/**/*.java']

    // extraSystemPath = '/my/path/to/npm'
}

I didn't really expect this to work, since I can't find instructions to include only the transpiler using gradle. I get the following error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'poc-jsweet'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find org.jsweet:jsweet-transpiler:3.0.0.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/org/jsweet/jsweet-transpiler/3.0.0/jsweet-transpiler-3.0.0.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project : > org.jsweet.jsweet-gradle-plugin:org.jsweet.jsweet-gradle-plugin.gradle.plugin:3.0.1 > gradle.plugin.org.jsweet:jsweet-gradle-plugin:3.0.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Is it possible to integrate just the jsweet transpiler into my project using this gradle plugin?

lgrignon commented 3 years ago

You just need to add the proper repositories, please see the README: https://github.com/lgrignon/jsweet-gradle-plugin

That being said, main artifacts should be made available in public repos, I will sync it when I find time.

As a side note, I have to say that I don't recommend using JSweet to transpile a react app. React JSweet's candy is very complicated. However, if your goal is just to transpile some Java code to make it available to your TS app, well, that's exactly what JSweet is good at. Just use the gradle plugin to transpile the Java source located in the input folder and you will be good to go.

lgrignon commented 3 years ago

Can I ask why did you specify "only transpiler"? Because it really seems like you want to use the gradle plugin :)

Skillzore commented 3 years ago

Ah, sorry if I am confusing. I simply don't know how it works. Yes, it does seem like I want to use the plugin to run the jsweet transpiler on some of my java code and get some typescript back to hook into to my react client. I do not intend on transpiling an entire app, no worries there.

I was trying to be as minimal as possible to not include any unnecessary jsweet parts. I have read the readme, I guess what I am wondering is if I need all the repos? What is the minimal setup I would need to run jsweet-transpiler on my java code?

lgrignon commented 3 years ago

The README is the recommended setup :)

You can also take a look at this build.gradle example: https://github.com/cincheo/jsweet-examples/

Skillzore commented 3 years ago

Alright, I'll try it out then. Thanks!

Skillzore commented 3 years ago

Hi again!

Following the readme, I now have this build file:

buildscript {
    repositories {
        mavenCentral()
        maven { url "http://repository.jsweet.org/artifactory/libs-release-local" }
        maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
        maven { url "http://repository.jsweet.org/artifactory/plugins-release-local" }
        maven { url "http://repository.jsweet.org/artifactory/plugins-snapshot-local" }
        maven { url "http://google-diff-match-patch.googlecode.com/svn/trunk/maven" }
    }
    dependencies {
        classpath('org.jsweet:jsweet-gradle-plugin:3.0.0') { //
            transitive = true }
    }
}

dependencies {
    compile group: 'org.jsweet', name: 'jsweet-transpiler', version: "3.0.0"
    compile group: 'org.jsweet', name: 'jsweet-core', version: "6"
    compile group: 'org.jsweet.candies', name: 'angular', version: "1.4.0-20170726"
    compile group: 'org.jsweet.candies', name: 'angular-route', version: "1.2.0-20170726"
}

compileJava {
    enabled = false
}

apply plugin: 'org.jsweet.jsweet-gradle-plugin'

jsweet {
    verbose = true
    encoding = 'UTF-8'
    sourceMap = true
    tsout = project.file('target/typescript')
    outDir = project.file('target/javascript')
    candiesJsOut = project.file('target/candies')
    targetVersion = 'ES6'
    includes = ['**/src/main/poc/validation.java']

    // extraSystemPath = '/my/path/to/npm'
}

Running ./gradlew tasks i get the following error: image

Adding the --stacktrace flag reveals an argument exception. image

The gradle build file and gradlew that I have are from a spring boot setup. Could it be that the plugin doesn't play well with spring boot gradle?

lgrignon commented 3 years ago

I think latest Gradle is unfortunately not supported, please see https://github.com/lgrignon/jsweet-gradle-plugin/issues/24

Please open a new issue if you notice new problems

Skillzore commented 3 years ago

Ah, sorry. Googled my error, weird I didn't get a hit on the stack trace in the issue you linked. I'll change my Gradle version and see if it helps.

lgrignon commented 3 years ago

Published: jsweet-transpiler jsweet-core j4ts jsweet-maven-plugin jsweet-gradle-plugin

on bintray & maven central