gradle 将多模块项目发布到 AWS Artifact 仅发布 META-INF
gradle publishing multi module project to AWS Artifact only publishes META-INF
我最近开始使用 gradle 并尝试将多模块项目发布到 AWS Artifact。我的子模块构建文件如下所示
- 模块:核心
buildscript {
dependencies {
classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:0.4.34"
}
}
plugins {
id "net.researchgate.release" version "2.8.0"
}
group "com.local"
apply plugin: "java"
apply plugin: "jsonschema2pojo"
apply plugin: "maven"
apply plugin: "net.researchgate.release"
jar {
baseName "core-schema"
}
release {
tagTemplate = 'core-${version}'
}
jsonSchema2Pojo {
source files("${projectDir}/src/main/resources/json")
generateBuilders = true
}
dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'javax.validation:validation-api:2.0.0.Final'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
}
afterReleaseBuild.dependsOn uploadArchives
- 火花示例
plugins {
id 'java'
id 'java-library'
id 'scala'
id 'com.github.johnrengelman.shadow' version '1.2.4'
}
apply plugin: 'scalaStyle'
scalaStyle {
configLocation = "${project.rootDir}/scalastyle_config.xml"
includeTestSourceDirectory = true
source = "src/main/scala"
testSource = "src/test/scala"
}
dependencies {
compile group: 'org.apache.spark', name: "spark-core_2.11", version: '2.4.2'
compile group: 'org.apache.spark', name: "spark-sql_2.11", version: '2.4.2'
}
configurations {
runtime.exclude module: 'spark-core_2.11'
runtime.exclude module: 'spark-sql_2.11'
}
compileScala.dependsOn(scalaStyle)
jar {
mainClassName = 'NONE'
baseName "spark-sample"
}
tasks.withType(ScalaCompile) {
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false
}
tasks.withType(ScalaCompile) {
configure(scalaCompileOptions.forkOptions) {
memoryMaximumSize = '1g'
jvmArgs = ['-XX:MaxPermSize=512m']
}
}
主应用程序构建文件如下所示:
plugins {
id 'java-library'
id 'maven-publish'
}
group "com.local"
subprojects { subproject ->
configurations {
deployer
}
dependencies {
deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = artifactName
version = version
from components.java
}
}
repositories {
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
现在,当我 运行 gradle build
时,我可以看到在相应的 build/libs/
目录下为所有模块和根项目创建了带有代码文件的 jars。但是,当我执行 gradle publish
时,我只看到根 jar 仅使用 MANIFEST.NF
文件发布,如下所示:
更新:
正如@nico 所建议的,我尝试在 allprojects{}
块中添加发布块,但它使用根项目名称发布每个项目并覆盖所有项目,如下面的日志所示。我也尝试在子项目 中添加发布块,但输出仍然相同。
2030009268:spark-store user$ gradle publishAllPublicationsToMavenRepository
> Task :core:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
> Task :spark-sample:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
更新根项目构建:
plugins {
id 'java-library'
id 'maven-publish'
}
group "com.local"
subprojects { subproject ->
configurations {
deployer
}
dependencies {
deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
allprojects {
apply plugin: 'maven-publish'
apply plugin: 'java-library'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = artifactName
version = version
from components.java
}
}
repositories {
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
}
关于您的主应用程序构建文件:
尝试将 publishing{} 块包含在 allprojects{} 块中,或者也将其添加到上述子项目{} 块中。目前发布规范仅适用于根项目级别。
我最近开始使用 gradle 并尝试将多模块项目发布到 AWS Artifact。我的子模块构建文件如下所示
- 模块:核心
buildscript {
dependencies {
classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:0.4.34"
}
}
plugins {
id "net.researchgate.release" version "2.8.0"
}
group "com.local"
apply plugin: "java"
apply plugin: "jsonschema2pojo"
apply plugin: "maven"
apply plugin: "net.researchgate.release"
jar {
baseName "core-schema"
}
release {
tagTemplate = 'core-${version}'
}
jsonSchema2Pojo {
source files("${projectDir}/src/main/resources/json")
generateBuilders = true
}
dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'javax.validation:validation-api:2.0.0.Final'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
}
afterReleaseBuild.dependsOn uploadArchives
- 火花示例
plugins {
id 'java'
id 'java-library'
id 'scala'
id 'com.github.johnrengelman.shadow' version '1.2.4'
}
apply plugin: 'scalaStyle'
scalaStyle {
configLocation = "${project.rootDir}/scalastyle_config.xml"
includeTestSourceDirectory = true
source = "src/main/scala"
testSource = "src/test/scala"
}
dependencies {
compile group: 'org.apache.spark', name: "spark-core_2.11", version: '2.4.2'
compile group: 'org.apache.spark', name: "spark-sql_2.11", version: '2.4.2'
}
configurations {
runtime.exclude module: 'spark-core_2.11'
runtime.exclude module: 'spark-sql_2.11'
}
compileScala.dependsOn(scalaStyle)
jar {
mainClassName = 'NONE'
baseName "spark-sample"
}
tasks.withType(ScalaCompile) {
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false
}
tasks.withType(ScalaCompile) {
configure(scalaCompileOptions.forkOptions) {
memoryMaximumSize = '1g'
jvmArgs = ['-XX:MaxPermSize=512m']
}
}
主应用程序构建文件如下所示:
plugins {
id 'java-library'
id 'maven-publish'
}
group "com.local"
subprojects { subproject ->
configurations {
deployer
}
dependencies {
deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = artifactName
version = version
from components.java
}
}
repositories {
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
现在,当我 运行 gradle build
时,我可以看到在相应的 build/libs/
目录下为所有模块和根项目创建了带有代码文件的 jars。但是,当我执行 gradle publish
时,我只看到根 jar 仅使用 MANIFEST.NF
文件发布,如下所示:
更新:
正如@nico 所建议的,我尝试在 allprojects{}
块中添加发布块,但它使用根项目名称发布每个项目并覆盖所有项目,如下面的日志所示。我也尝试在子项目
2030009268:spark-store user$ gradle publishAllPublicationsToMavenRepository
> Task :core:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
> Task :spark-sample:publishMavenJavaPublicationToMavenRepository
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
Multiple publications with coordinates 'com.local:spark-sample:0.0.5-SNAPSHOT' are published to repository 'maven'. The publications will overwrite each other!
更新根项目构建:
plugins {
id 'java-library'
id 'maven-publish'
}
group "com.local"
subprojects { subproject ->
configurations {
deployer
}
dependencies {
deployer 'org.kuali.maven.wagons:maven-s3-wagon:1.2.1'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
allprojects {
apply plugin: 'maven-publish'
apply plugin: 'java-library'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = artifactName
version = version
from components.java
}
}
repositories {
maven {
url "${aws_url}"
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
}
}
}
关于您的主应用程序构建文件:
尝试将 publishing{} 块包含在 allprojects{} 块中,或者也将其添加到上述子项目{} 块中。目前发布规范仅适用于根项目级别。