Create custom protoc plugin in Java

Uraty :

I'm trying to write a custom ProtoC plugin, but I can't make the protoc working with jar files. Seems it tries to run it as an application and I've got:

.../libs/plugin-java-protobuf-1.0-jvm8.jar: program not found or is not executable

I've seen solution, where created .sh script with java -jar ..., but I want to use my plugin with Gradle Protobuf plugin and composite build (includeBuild ...).

I have found kroto-plus plugin https://github.com/marcoferrer/kroto-plus/blob/master/protoc-gen-kroto-plus/build.gradle that solved this problem. It's jar seem executable.

But unfortunately, I can't understand what exactly I need to do. I have tried bootJar:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.21'
    id 'org.springframework.boot'
}

jar {
    archiveClassifier = 'jvm8'
    manifest {
        attributes 'Main-Class': 'plugin.PluginKt'
    }
}

bootJar {
    archiveClassifier = 'jvm8'
}

But result is the same:

.../libs/plugin-java-protobuf-1.0-jvm8.jar: program not found or is not executable

So how can I make jar truly executable?

Uraty :

Stupid of me, just forgot to set launchScript(). So the next configuration works:

plugins {
    id 'org.springframework.boot' version '2.1.5.RELEASE'
}

jar {
    enabled = false
    archiveClassifier = 'jvm8'
}

bootJar {
    launchScript()
    archiveClassifier = 'jvm8'
    mainClassName = 'plugin.PluginKt'
}

jar.dependsOn(bootJar)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=163185&siteId=1