使用你自己的Java库在另一个项目中?

huangapple go评论96阅读模式
英文:

Using your own Java library in another project?

问题

尽管我已经使用Java开发了一段时间,但我最近才决定尝试创建自己的库。我已经创建了它,并在Intellij Idea中有第二个项目,但我不知道如何在第二个项目中使用这个库。到目前为止,这是我所拥有的:

在我的库中,build.gradle如下:

apply plugin: 'java-library'
version = '0.0.1'

repositories {
    jcenter()
}

jar {
    manifest {
        attributes(
            'Implementation-Title': project.name,
            'Implementation-Version': project.title
        )
    }
}

dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:23.0'
    testImplementation 'junit:junit:4.12'
}

我猜我的问题是,我如何将我的库实现到第二个项目中,以便我可以在第二个项目中使用它(并正确测试它)?我尝试在网络上搜索答案,但似乎找不到一个对我有意义的解释。

我在Intellij Idea的同一个窗口中有一个多项目。

英文:

So despite developing with Java for quite a while, I've only just decided to give making my own library a go. I've created it, and have a second project within Intellij Idea, but I don't know how to use said library in the second project. This is what I have so far:

In my library, build.gradle is:

apply plugin: 'java-library'
version = '0.0.1'

repositories {
    jcenter()
}

jar {
    manifest {
        attributes(
            'Implementation-Title': project.name,
            'Implementation-Version': project.title
        )
    }
}

dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:23.0'
    testImplementation 'junit:junit:4.12'
}

I guess what my question is, is how do I implement my library into the second project so that I can use it (and test it properly) in the second project? I've tried to search the net to find the answer to this and cannot seem to get an explanation that makes sense to me.

I have a multi-project in the same window of Intellij Idea.

答案1

得分: 1

我觉得官方指南对于如何构建自定义库非常有意义。您可以按照那个方法:构建 Java 库
要查找使用 JUnit 进行测试的部分,您可以按照这些规则

英文:

I find the official guide very meaningful about how to build a custom library.You can follow that way : Building Java Libraries.
To look for the testing part with JUnit, you can follow that rules.

huangapple
  • 本文由 发表于 2020年4月9日 06:02:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/61110745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定