V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
heavyrainn
V2EX  ›  程序员

菜 X 提问…用 gradle 打包自己写的 kotlin 工具包,打成的 jar 其他项目无法 import 里面的方法怎么办…

  •  
  •   heavyrainn · 2020-07-31 10:52:58 +08:00 · 1291 次点击
    这是一个创建于 1358 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目是用 IDEA 的 gradle 项直接创建的,项目路径如下:

    src/
    ├── main
    │   ├── java
    │   ├── kotlin
    │   │   └── org
    │   │       └── lxx
    │   │           └── dxtool
    │   │               ├── dxcmd
    │   │               │   └── DxCmd.kt
    │   │               ├── dxfileext
    │   │               │   └── DxFileExt.kt
    │   │               ├── dxjdbc
    │   │               │   └── DxJdbc.kt
    │   │               ├── dxjsonlog
    │   │               │   └── DxJsonLog.kt
    │   │               ├── dxlog
    │   │               │   └── DxLog.kt
    │   │               ├── dxnats
    │   │               │   └── DxNATS.kt
    │   │               ├── dxresources
    │   │               │   └── DxResources.kt
    │   │               ├── dxssh
    │   │               │   └── DxSSH.kt
    │   │               ├── dxtcp
    │   │               │   └── DxTCP.kt
    │   │               ├── dxtemplate
    │   │               │   └── DxTemplate.kt
    │   │               └── dxtime
    │   │                   └── DxTime.kt
    │   └── resources
    └── test
        ├── java
        ├── kotlin
        └── resources
    

    gradle 文件内容如下:

    plugins {
        id 'org.jetbrains.kotlin.jvm' version '1.3.72'
    }
    
    group 'org.example'
    version '1.0-SNAPSHOT'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
        compile 'com.github.sisyphsu:dateparser:1.0.4'
        compile group: 'com.jcraft', name: 'jsch', version: '0.1.55'
        compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
        compile group: 'commons-codec', name: 'commons-codec', version: '1.14'
        compile 'commons-net:commons-net:3.6'
        compile 'org.freemarker:freemarker-gae:2.3.30'
    }
    
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    
    jar {
        from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
    }
    
    

    执行 gradle build 命令打包,打完包之后其他项目使用 compile files('jar 包的路径 /dxtool-1.0-SNAPSHOT.jar')之后,却无法 import 到包里面的方法,请问如何定位和解决呢,感谢大家

    1 条回复    2020-07-31 11:30:58 +08:00
    heavyrainn
        1
    heavyrainn  
    OP
       2020-07-31 11:30:58 +08:00
    通过 IDEA 看 External Libraries,发现我自己的 jar 包旁边会写一个 library root,请问和这个有关系么?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2619 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:46 · PVG 09:46 · LAX 18:46 · JFK 21:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.