区块链技术博客
www.b2bchain.cn

Gradle 6.X 上传 aar 到 Nexus 私服求职学习资料

本文介绍了Gradle 6.X 上传 aar 到 Nexus 私服求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

昨天把 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) {             pom {                 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 = 'john.doe@example.com'                     }                 }                 scm {                     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);

}

昨天把 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) {             pom {                 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 = 'john.doe@example.com'                     }                 }                 scm {                     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);

}

昨天把 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) {             pom {                 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 = 'john.doe@example.com'                     }                 }                 scm {                     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);

}

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Gradle 6.X 上传 aar 到 Nexus 私服求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们