How to build Groovy JAR w/ Gradle and publish it to in-house repo

后端 未结 2 1729
你的背包
你的背包 2021-01-05 12:41

I have a Groovy project and am trying to build it with Gradle. First I want a package task that creates a JAR by compiling it against its dependencies. Then I n

2条回答
  •  盖世英雄少女心
    2021-01-05 13:43

    package is a keyword in Java/Groovy, and you'd have to use a different syntax to declare a task with that name.

    Anyway, the task declaration for package should be removed, as the jar task already serves that purpose. The jar task configuration (jar { from ... }) should be at the outermost level (not nested inside another task), but from configurations.compile is unlikely what you want, as that will include Jars of compile dependencies into the Jar (which regular Java class loaders can't deal with), rather than merging them into the Jar. (Are you even sure you need a fat Jar?)

    Likewise, the publish task declaration should be removed, and replaced with publishing { publications { ... } }.

    Also, the buildscript block should probably be removed, and repositories { ... } and dependencies { ... } moved to the outermost level. ( buildscript { dependencies { ... } } declares dependencies of the build script itself (e.g. Gradle plugins), not the dependencies of the code to be compiled/run.)

    I suggest to check out the many self-contained example builds in the samples directory of the full Gradle distribution (gradle-all).

提交回复
热议问题