Almost feeling like spamming after my third question, cause my questions seem so trivial. But I just don't find any help in Gradle Docs for my cases and also other asked questions on stackoverflow weren't helping.
This time: I can't use the maven-publish
plugin in my own standalone custom plugin. The code of my plugin so far:
package com.sample.gradle;
import org.gradle.api.Project;
import org.gradle.api.Plugin;
public class SampleGradlePlugin implements Plugin<Project> {
public void apply(Project project) {
project.apply plugin: 'application'
project.apply plugin: 'maven-publish'
project.apply plugin: 'maven'
project.publishing.publications {
maven(MavenPublication) {
groupId project.group
artifactId project.name
version=project.version
from components.java
}
}
project.uploadArchives {
repositories {
mavenDeployer {
repository(url: project.Repo_Upload_Internal){
authentication(userName: project.Repo_Upload_User, password: project.Repo_Upload_Pass)
}
snapshotRepository(url: project.Repo_Upload_Snapshot){
authentication(userName: project.Repo_Upload_User, password: project.Repo_Upload_Pass)
}
}
}
}
//this try/catch is not important for my question
try{
project.repositories {
maven {
url project.Repo_Gp_Internal
credentials {
username project.Repo_Gp_User;
}
}
}
}
catch(MissingPropertyException e){
println "Info: '"+e.getProperty()+"' not declared in \\"+project.name+"\\gradle.properties"
}
}
}
The publishing
closure is the important part that brings me this error, when I use my plugin in one of my projects:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\quastc\Desktop\Gradle_Projects\Application_RootProject\buil
d.gradle' line: 3
* What went wrong:
A problem occurred evaluating root project 'Application_RootProject'.
> Failed to apply plugin [id 'sample.sample-groovy-plugin']
> Cannot create a Publication named 'MavenPublication' because this container
does not support creating elements by name alone. Please specify which subtype
of Publication to create. Known subtypes are: MavenPublication
Where's my mistake? What did I forget?
If somebody answers, PLEASE let me know HOW you got your knowledge.