ArtifactoryPublish 因空指针异常而失败

Posted

技术标签:

【中文标题】ArtifactoryPublish 因空指针异常而失败【英文标题】:ArtifactoryPublish fails with null pointer exception 【发布时间】:2016-11-11 16:41:17 【问题描述】:

我有一个 java 库,我想将它上传到 jfrog artifactory。但无论我做什么,我都会得到一个空指针异常:

Execution failed for task :util-lib-java:artifactoryPublish. java.lang.NullPointerException (no error message)

它在今年 10 月 3 日运行良好,但在 10 日失败。然后我们引用了版本:classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.*",我可以看到 jfrog 在这些日期之间将他们的库从 4.4.5 更新到 4.47。但是现在当我尝试使用各种版本时,我只会得到上面指定的错误。

我的 build.gradle 看起来像:

buildscript 
repositories 
    jcenter()
    maven 
        url "$artifactory_contextUrl/plugins-release"
        credentials 
            username = "$artifactory_user"
            password = "$artifactory_password"
        
    


dependencies 
    //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
    classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.2"



apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'


repositories
    
        mavenCentral()
        maven 
            url "$artifactory_contextUrl/libs-release-local"
        
        maven 
            url "$artifactory_contextUrl/libs-snapshot-local"
        
    

// android project is also using this library, so java version cannot be 1.8
sourceCompatibility = 1.7
targetCompatibility = 1.7

publishing 
publications 
    mavenJava(MavenPublication) 

        // Set the base name of the artifacts
        artifactId 'util-lib-java'
        groupId group
        version version

        from components.java
    




artifactory 
contextUrl = "$artifactory_contextUrl"   //The base Artifactory URL if not overridden by the publisher/resolver
publish 
    repository 
        if ( project.version.endsWith('-SNAPSHOT') ) 
            repoKey =  'libs-snapshot-local'
         else 
            repoKey =  'libs-release-local'
        
        username = "$artifactory_user"
        password = "$artifactory_password"
        maven = true
    
    defaults 
        publications ('mavenJava')
    


顶层 build.gradle 看起来像:

buildscript 
repositories 
    jcenter()

dependencies 
    classpath 'com.android.tools.build:gradle:2.1.3'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files



allprojects 
version = '1.0'
group = 'com.companyname'

repositories 
    jcenter()


我们正在使用 gradle-2.14.1-bin.zip 包装器。

来自构建的堆栈跟踪:

 * Exception is:
 org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':util-lib-java:artifactoryPublish'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.NullPointerException
    at org.jfrog.gradle.plugin.artifactory.task.BuildInfoBaseTask.prepareAndDeploy(BuildInfoBaseTask.java:346)
    at org.jfrog.gradle.plugin.artifactory.task.BuildInfoBaseTask.collectProjectBuildInfo(BuildInfoBaseTask.java:132)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:228)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:621)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:604)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)

我在这里缺少什么? This issue别帮我

【问题讨论】:

问题解决了吗? 【参考方案1】:

对于遇到此问题的人应注意,应使用最新版本解决该问题:4.4.10

https://github.com/JFrogDev/build-info/issues/101

【讨论】:

【参考方案2】:

对于发布,您必须删除 gradle.propertieslocal.properties 中的这些行:

org.gradle.configureondemand=true
org.gradle.daemon=true

您还必须将其添加到主 build.gradle 文件中。

allprojects 
    apply plugin: 'com.jfrog.artifactory'
    ...

之后发布应该可以工作了。

【讨论】:

好的,试试看。 gradle 设置的建议似乎无关紧要。也许说明为什么应该这样设置它们会有所帮助,这两个设置会极大地影响构建性能。

以上是关于ArtifactoryPublish 因空指针异常而失败的主要内容,如果未能解决你的问题,请参考以下文章

Android 应用程序不断因空指针异常而崩溃

将 Geopoint 转换为 Location 时出现空指针异常

Android列表视图返回null?

Java 8 新特性 Optional

为啥标量值函数会因空参数而失败?

SQL 查询因空结果而失败