Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Compilation failure when using the org.hidetake.ssh plugin #763

Closed
ingokegel opened this issue Mar 16, 2018 · 9 comments
Closed

Compilation failure when using the org.hidetake.ssh plugin #763

ingokegel opened this issue Mar 16, 2018 · 9 comments

Comments

@ingokegel
Copy link

The compilation of the following build file fails with Gradle 4.6:

import org.hidetake.groovy.ssh.core.Remote
import org.hidetake.groovy.ssh.core.RunHandler
import org.hidetake.groovy.ssh.session.SessionHandler

plugins {
	id("org.hidetake.ssh") version "2.9.0"
}

ssh.run(delegateClosureOf<RunHandler> {
	session((ssh.remotes as Map<*, *>)["server"]!! as Remote, delegateClosureOf<SessionHandler> {
		get(hashMapOf("from" to "remoteFile.txt", "into" to "localFile.txt"))
	})
})

with the error message:

 Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
	class org.hidetake.groovy.ssh.core.Remote, unresolved supertypes: org.hidetake.groovy.ssh.session.transfer.FileTransferSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.session.execution.SudoSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.operation.ShellSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.operation.CommandSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.session.SessionSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.connection.ConnectionSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.connection.ProxyConnectionSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.connection.HostAuthenticationSettings.Trait.FieldHelper, org.hidetake.groovy.ssh.connection.UserAuthenticationSettings.Trait.FieldHelper
@JLLeitschuh
Copy link
Contributor

Is this an issue with the Kotlin compiler or Gradle not correctly resolving dependencies?
A good way to figure this out would be to try to use that plugin as a dependency in some project and try to use those types.

@eskatos eskatos added this to the 1.1.0 milestone Apr 3, 2018
@weitjong
Copy link

weitjong commented Apr 5, 2018

Using kotlin-dsl 0.16.3.

plugins {
    id("org.hidetake.ssh") version "2.9.0"
}
remotes {
    create("webServer") {
        host = "192.168.1.101"
    }
}

As soon as the 'host' or any property from the Remote class is used, the script compilation failed with the similar error message.

FWIW, currently I workaround the issue by writing the remotes configuration and custom SSH task using a separate Groovy script, and then apply the groovy script in my module's build.gradle.kts (similar to https://github.com/gradle/kotlin-dsl/blob/master/samples/groovy-interop/build.gradle.kts).

@altavir
Copy link

altavir commented Sep 11, 2018

Just hit the same wall. Also it would be good to have complimentary kotlin dsl for this case since there seems to be no simple kotlin- or java-based way to upload something via ssh. Using Jsch directly is complicated.

@calvertdw
Copy link

calvertdw commented Sep 20, 2018

@weitjong Is it possible for you to share some example code for doing that?

Oh, a simple apply(from = "groovy.gradle") and a separate groovy.gradle does the trick:

remotes {
   serverName{
      host = "some.host"
      user = "username"
   }
}

task deploy(dependsOn: installDist) {
   doLast {
      ssh.run{
         session(remotes.serverName) {
            execute("some stuff")
         }
      }
   }
}

@rnett
Copy link
Member

rnett commented Oct 13, 2018

I still get

Duplicate method name "getExt" with signature "Lorg.gradle.api.NamedDomainObjectContainer;)Lorg.gradle.api.plugins.ExtraPropertiesExtension;" in class file org/gradle/kotlin/dsl/AccessorsKt

when using a separate file.

Not sure if this is the same issue, should I make a new one?

@eskatos
Copy link
Member

eskatos commented Apr 19, 2019

This is a Groovy/Kotlin interoperability problem. The Remote type makes use of Groovy traits that confuse the Kotlin compiler. Latest 2.10.1 version of that plugin is also affected.

@eskatos
Copy link
Member

eskatos commented Apr 24, 2019

Here is how to work around the plugin interoperability issue using withGroovyBuilder {}:

plugins {
    id("org.hidetake.ssh") version "2.10.1"
}

remotes {
    withGroovyBuilder {
        "create"("webServer") {
            setProperty("host", "127.0.0.1")
        }
    }
}

@eskatos eskatos closed this as completed Apr 24, 2019
@calvertdw
Copy link

calvertdw commented May 22, 2019

@eskatos Struggling to use your workaround in practice. I have:

var myRemote: Any? = null
remotes {
   myRemote= withGroovyBuilder {
      "create"("remoteName") {
         setProperty("host", "127.0.0.1")
         setProperty("user", "username")
         setProperty("password", properties["password"]!!)
         setProperty("knownHosts", AllowAnyHosts.instance)
      }
   }
}

val deploy by tasks.registering {
   dependsOn(":installDist")

   doLast {
      ssh.run {
         delegateClosureOf<RunHandler> {
            session(myRemote, delegateClosureOf<SessionHandler> {
                       execute("mkdir -p /remote/dir")
...

Currently stuck on the error: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class org.hidetake.groovy.ssh.core.Remote, unresolved supertypes: FieldHelper, FieldHelper, FieldHelper...

In summary the issue is passing the remote to the RunHandler#session method. (https://github.com/int128/groovy-ssh/blob/bd95e54864d128e304c1502e45d76e9943242dac/core/src/main/groovy/org/hidetake/groovy/ssh/core/RunHandler.groovy#L4)

Edit: Use SessionHandler.
Edit 2: I also tried var myRemote: Remote = remotes.withGroovyBuilder { "get"("remoteName") } as Remote and still get the same error.

@eskatos
Copy link
Member

eskatos commented Jun 25, 2019

As long as you need to reference the Remote type or an instance from Kotlin it won't work.
Did you try val remote: Any = withGroovyBuilder { ... } ?

The real fix would be that int128/gradle-ssh-plugin#317 be addressed by the plugin author or the community.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants