70

I am facing a problem when trying to install a generated jar into my local Maven Repository. The message error just show me 'task 'publish' is not found'

I am using this Gradle Script:

buildscript {
    ext {
        springBootVersion = '1.3.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'

jar {
    baseName = 'mongofoundry'
    version = '1.0.0'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7


repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-data-mongodb')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}


eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

Do you have some idea Why I am reading that error message? Thanks.

UPDATED

Running the command as @RaGe mentioned, solved the problem:

gradle publishToMavenLocal.
4

4 回答 4

112

The correct task to publish artifacts to local maven is

gradle publishToMavenLocal
于 2016-02-01T16:27:38.487 回答
4

Check Maven locally

For developing and testing it is useful to check library locally

gradle settings for apply plugin: 'com.android.library' not apply plugin: 'java-library'(where you can use it by default)

apply plugin: 'maven-publish'

//simple settings
project.afterEvaluate {
    publishing {
        publications {
            library(MavenPublication) {
                //setGroupId groupId
                setGroupId "com.company"
                //setArtifactId artifactId
                setArtifactId "HelloWorld"
                version "1.1"

                artifact bundleDebugAar

/* add a dependency into generated .pom file
                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', 'com.company')
                    dependencyNode.appendNode('artifactId', 'HelloWorld-core')
                    dependencyNode.appendNode('version', '1.1')

                }
*/
            }
        }
    }
}

to run it using command line or find this command in Gradle tab

./gradlew publishToMavenLocal

Location

artefact will be added into .m2 folder

//Unix
~/.m2

//Windows
C:\Users\<username>\.m2

//For example
/Users/alex/.m2/repository/<library_path>/<version>/<name>.<extension>

build folder

<project_path>/build/outputs/<extension>

other repositories location

~/.gradle/caches/modules-2/files-2.1/<group_id>/<artifact_id>/<version>/<id>

//For example
/Users/alex/.gradle/caches/modules-2/files-2.1/com.company/HelloWorld/1.1/c84ac8bc425dcae087c8abbc9ecdc27fafbb664a

To use it add mavenLocal(). It is important to place it as a first item for prioritise it, which is useful for internal dependencies

buildscript {
    repositories {
        mavenLocal()
    }

allprojects {
    repositories {
        mavenLocal()
    }
}

and

dependencies {
    implementation 'com.company:HelloWorld:+'
}

*Also remember if you use a kind of shared.gradle file (via apply from) you should set path which is relevant to project.gradle (not shared.gradle)

[iOS CocoaPod local]

于 2021-01-15T14:43:16.230 回答
2

Add maven plugin to your project and then: gradle clean install

于 2020-06-29T22:27:25.497 回答
0

This is how I did it with Kotlin DSL (build.gradle.kts) for my Android library:

plugins {
    id("maven-publish")
    // OR simply
    // `maven-publish`
    // ...
}

publishing {
    repositories {
        // Local repository which can be published to first to check artifacts
        maven {
            name = "LocalTestRepo"
            url = uri("file://${buildDir}/local-repository")
        }
    }
    publications {
        // ...
    }
}

You can create all the publications with the following command:

./gradlew publishAllPublicationsToLocalTestRepoRepository

Or just a single publication with this command:

./gradlew publishReleasePublicationToLocalTestRepoRepository

See Gradle documentations: Maven Publish Plugin for more information.

于 2022-02-18T16:29:44.320 回答