5

Gradle 6.X 上传 aar 到 Nexus 私服

 3 years ago
source link: https://xiaozhuanlan.com/topic/1892435067
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

昨天把 gradle 升级到 6.0 以后,发现这傻逼的 google 又直接干 API,以前上报的全部脚本都没法用了。我们原先上报一个 aar,是直接引入

apply plugin: 'maven'

结果新版本直接这个插件都被干掉了,看了官网文档以后才知道,换成了

apply plugin: 'maven-publish'

然后里面的API也全换掉了。

解决 sourcesJar Task 过时

然后 sourcesJartask 也报了个警告,说classifier已经过时了,以前代码是这样写的:

task sourcesJar(type: Jar) {
classifier = 'sources'

这个好解决,看一眼源码,要用 archiveClassifier 去替代:

* Sets the classifier.
* @deprecated Use {@link #getArchiveClassifier()}
@Deprecated
public void setClassifier(@Nullable String classifier) {
// This is used by the Kotlin plugin, we should upstream a fix to avoid this API first.
// DeprecationLogger.deprecateProperty(AbstractArchiveTask.class, "classifier").replaceWith("archiveClassifier").withDslReference().nagUser();
archiveClassifier.convention(classifier);
archiveClassifier.set(classifier);

内部就是做了个代理,改成了新API,就解决了。

task sourcesJar(type: Jar) {
archiveClassifier.convention('sources')
archiveClassifier.set('sources')

解决 maven plugin 过时

然后是上传的Task,以前的代码是这样写的

uploadArchives {
def object
repositories {
mavenDeployer {
pom.groupId = project.group
pom.artifactId = project.description
pom.version = LIB_VERSION

现在改成了可以用自定义 Task 来替代,例如:

publishing {
publications {
kymjs(MavenPublication) {
name = 'kymjs'
description = 'A concise description of my library'
url = 'http://www.kymjs.com/library'
properties = [
myProp: "value",
"prop.with.dots": "anotherValue"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
developers {
developer {
id = 'johnd'
name = 'John Doe'
email = '[email protected]'
connection = 'scm:git:git://example.com/my-library.git'
developerConnection = 'scm:git:ssh://example.com/my-library.git'
url = 'http://kymjs.com/my-library/'

在之后就是查代码了,查看MavenPublication类声明,原来就是以前的pom对象做了个封装。

```
@HasInternalProtocol
public interface MavenPublication extends Publication {
/**
* The POM that will be published.
*
* @return The POM that will be published.
*/
MavenPom getPom();

* Configures the POM that will be published.
* The supplied action will be executed against the {@link #getPom()} result. This method also accepts a closure argument, by type coercion.
* @param configure The configuration action.
void pom(Action<? super MavenPom> configure);
* Provides the software component that should be published.
* <ul>
* <li>Any artifacts declared by the component will be included in the publication.</li>
* <li>The dependencies declared by the component will be included in the published meta-data.</li>
* </ul>
* Currently 3 types of component are supported: 'components.java' (added by the JavaPlugin), 'components.web' (added by the WarPlugin)
* and `components.javaPlatform` (added by the JavaPlatformPlugin).
* For any individual MavenPublication, only a single component can be provided in this way.
* The following example demonstrates how to publish the 'java' component to a Maven repository.
* <pre class='autoTested'>
* plugins {
* id 'java'
* id 'maven-publish'
* publishing {
* publications {
* maven(MavenPublication) {
* from components.java
* </pre>
* @param component The software component to publish.
void from(SoftwareComponent component);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK