Gradle创建pom失败

时间:2018-11-22 18:34:59

标签: maven android-studio gradle

我想用Gradle创建pom.xml。 但是失败了。

这是我的build.gradle(项目)

   // Top-level build file where you can add configuration options common      to all sub-projects/modules.
buildscript {
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

task writeNewPom {
doLast {
    pom {
        project {
            inceptionYear '2008'
            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    distribution 'repo'
                }
            }
        }
    }.writeTo("$buildDir/pom.xml")
}
}

和我的build.gradle(模块)

apply plugin: 'com.android.application'

apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.ludev-studio'

apply plugin: 'maven'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.ludevstudio.colorpicker"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-     android.txt'), 'proguard-rules.pro'
    }
}
buildToolsVersion '28.0.3'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
implementation project(':colorpicker')
}

这是输出,然后我用gradlew.bat执行了writeNewPom任务:

FAILURE: Build failed with an exception.

* Where:
Build     file 'C:\Users\lucad\Documents\programmierung\Projekte\Java\Androidlibraries\Colo    rpicker\build.gradle' line: 32

* What went wrong:
Execution failed for task ':writeNewPom'.
> Could not find method pom() for arguments [build_1nb7g16o7col6erw9g4aech65     $_run_closure3$_closure5  $_closure6@30d7b2ef] on task ':writeNewPom' of type org.gradle.api.DefaultTask.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to     get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for      task ':writeNewPom'.
    at       org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions    (ExecuteActionsTaskExecuter.java:103)
    at     org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute  (ExecuteActionsTaskExecuter.java:73)
    at  org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execu    te(OutputDirectoryCreatingTaskExecuter.java:51)
    at    org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at     org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.exe cute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute   (ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute (SkipEmptySourceFilesTaskExecuter.java:101)
    at  org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at  org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute  (CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at  org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
    at    org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at   org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run (DefaultBuildOperationExecutor.java:110)
    at  org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
    at o rg.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run  (ManagedExecutorImpl.java:46)
    at   org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by:     org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method pom() for arguments [build_1nb7g16o7col6erw9g4aech65$_run_closure3$_closure5$_closure6@30d7b2ef] on task ':writeNewPom' of type org.gradle.api.DefaultTask.
    atorg.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:179)
    at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:164)
    at org.gradle.api.DefaultTask_Decorated.invokeMethod(Unknown Source)
    at build_1nb7g16o7col6erw9g4aech65$_run_closure3$_closure5.doCall(C:\Users\lucad\Documents\programmierung\Projekte\Java\Androidlibraries\Colorpicker\build.gradle:32)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:726)
    at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:699)
    at     org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run        (ExecuteActionsTaskExecuter.java:124)        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperation    Worker.execute(DefaultBuildOperationExecutor.java:336)
    at     org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperation    Worker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute      (DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run    (DefaultBuildOperationExecutor.java:110)
    at     org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction    (ExecuteActionsTaskExecuter.java:113)
    at   org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions    (ExecuteActionsTaskExecuter.java:95)
    ... 30 more


* Get more help at https://help.gradle.org

BUILD FAILED in 8s
1 actionable task: 1 executed

我对丢失的Maven插件提出了一些建议,但就像您在gradle.build中看到的那样,我添加了该插件。 那么,该怎么办?

1 个答案:

答案 0 :(得分:0)

从您的踪迹

Caused by:     org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method pom() for arguments [build_1nb7g16o7col6erw9g4aech65$_run_closure3$_closure5$_closure6@30d7b2ef] on task ':writeNewPom' of type org.gradle.api.DefaultTask.

Gradle找不到任何合适的类型来委托pom()方法,那是因为您忘记了

apply plugin: 'maven'

在您的项目 build.gradle中。只需将以上行放在您的项目 build.gradle中,一切都会很好。