生成和使用不带POM的Gradle依赖

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

Generate and consume gradle dependency without POM

问题

我正试图生成我的Gradle项目的.jar文件,但是当我使用Maven发布来生成时,它也会生成一个.pom文件。

问题是,我有另一个项目,在它之前实现了这个依赖项,之前它只会寻找.jar文件,现在却在所有其他项目中寻找.pom文件,我想要做的是,让项目在使用"publishing"任务时停止生成.pom文件,或者在实现它时停止寻找其他项目的.pom文件,以便它们能够正常工作。

以下是在项目A中生成.jar文件的代码,与项目B中的代码相对应,项目B使用了项目A,并且寻找.pom文件:

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = 'com.proteccion.myproject'
            artifactId = 'myproject-base'
            version = '1.0.1'
            from components.java
        }   
    }
    repositories {
        maven {
            name = 'artifactory'
            url 'https://url/artifactory/MyProject'
            credentials {
                username System.getenv("ARTIFACTORY_USER") 
                password System.getenv("ARTIFACTORY_PWD")  
            }
        }
    }
}

repositories {
    jcenter()
    maven {
        url 'https://url/artifactory/MyProject'
        credentials {
            username System.getenv("ARTIFACTORY_USER") 
            password System.getenv("ARTIFACTORY_PWD")  
        }
    }
}

也许可以使用Gradle中等效的方式来实现:

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = 'com.proteccion.myproject'
            artifactId = 'myproject-base'
            version = '1.0.1'
            from components.java
        }   
    }
}
英文:

I am trying to generate the .jar of my Gradle project but when it is generated using Maven publishing it is also generating a .pom file.

The problem is that I have another project that when it implements this dependency before it only looked for .jar and now it looks for .pom in all the others, what I want to do is that the project stops generating a .pom using the "publishing" task or that when implement it stop looking for the .pom files for the others to work.

Here is the code to generate the .jar in Artifactory project A with the one in project B that uses A and looks for the .pom:

publishing {
    publications {
        mavenJava(MavenPublication) {
              groupId = 'com.proteccion.myproject'
              artifactId = 'myproject-base'
              version = '1.0.1'
            from components.java
        }   
    }
    repositories {
        maven {
            name = 'artifactory'
            url 'https://url/artifactory/MyProject'
            credentials {
                username System.getenv("ARTIFACTORY_USER") 
                password System.getenv("ARTIFACTORY_PWD")  
            }
        }
    }
}

repositories {
    jcenter()
    maven {
	    url 'https://url/artifactory/MyProject'
	    credentials {
                    username System.getenv("ARTIFACTORY_USER") 
                    password System.getenv("ARTIFACTORY_PWD")  
                }
    }
}

Perhaps with a Gradle equivalent of this segment:

publishing {
    publications {
        mavenJava(MavenPublication) {
              groupId = 'com.proteccion.myproject'
              artifactId = 'myproject-base'
              version = '1.0.1'
            from components.java
        }   
    }

答案1

得分: 4

最终这对我起作用了:

metadataSources {
    artifact()
}

强制仅搜索 jar 文件。完整的配置:

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = 'com.company.myproject'
            artifactId = 'myproject-base'
            version = '1.0.1'
            from components.java
        }
    }
    repositories {
        maven {
            name = 'artifactory'
            url 'https://url/artifactory/MyProject'
            credentials {
                username System.getenv("ARTIFACTORY_USER")
                password System.getenv("ARTIFACTORY_PWD")
            }
        }
    }
}

repositories {
    jcenter()
    maven {
        url 'https://url/artifactory/MyProject'
        credentials {
            username System.getenv("ARTIFACTORY_USER")
            password System.getenv("ARTIFACTORY_PWD")
        }
        metadataSources {
            artifact()
        }
    }
}

文档(示例18):
https://docs.gradle.org/current/userguide/dependency_management.html

英文:

Finally this worked for me:

metadataSources {
            artifact()
        }

Forces to search only for the jar file.
The complete configuration:

publishing {
publications {
    mavenJava(MavenPublication) {
          groupId = 'com.company.myproject'
          artifactId = 'myproject-base'
          version = '1.0.1'
        from components.java
    }   
}
repositories {
    maven {
        name = 'artifactory'
        url 'https://url/artifactory/MyProject'
        credentials {
            username System.getenv("ARTIFACTORY_USER") 
            password System.getenv("ARTIFACTORY_PWD")  
        }
    }
}
}

repositories {
jcenter()
maven {
    url 'https://url/artifactory/MyProject'
    credentials {
                username System.getenv("ARTIFACTORY_USER") 
                password System.getenv("ARTIFACTORY_PWD")  
            }
    metadataSources {
            artifact()
    }
}
}

Documentation (Example 18):
<https://docs.gradle.org/current/userguide/dependency_management.html>

答案2

得分: 2

[示例 17. 支持无元数据的Maven仓库][1]

    repositories {
        maven {
            url "http://repo.mycompany.com/repo"
            metadataSources {
                mavenPom()
                artifact()
            }
        }
    }


  [1]: https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:supported_metadata_sources
英文:

Example 17. Maven repository that supports artifacts without metadata

repositories {
    maven {
        url &quot;http://repo.mycompany.com/repo&quot;
        metadataSources {
            mavenPom()
            artifact()
        }
    }
}

huangapple
  • 本文由 发表于 2020年9月15日 13:43:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63895799.html
匿名

发表评论

匿名网友

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

确定