Hello All,
For the life of me I cannot find a simple example on how to create a project using JIRA's java api. I am getting my feet wet into the api and groovy so I don't know much. I am very familiar with the REST api however I do not want to use that because it is limited in terms of setting schemes.
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.project.ProjectCreationData
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.util.ErrorCollection
//def user = ComponentAccessor.getUserManager().getUserByName('admin')
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName('admin')
ProjectCreationData.Builder builder = new ProjectCreationData.Builder()
builder.withKey('KEY123').withName('KEY123').withLead(user)
ProjectCreationData data = builder.build()
Project validatedProject = ComponentAccessor.getProjectManager().createProject(user,data);The error I get is:
java.lang.IllegalStateException
at com.google.common.base.Preconditions.checkState(Preconditions.java:158)
at com.atlassian.jira.project.DefaultProjectManager.createProject(DefaultProjectManager.java:177)
at com.atlassian.jira.project.CachingProjectManager.createProject(CachingProjectManager.java:143)
at com.atlassian.jira.project.ProjectManager$createProject.call(Unknown Source)
at test.run(test.groovy:19)
Will using scriptrunner and the java api allow me to set more complicated schemes like issue, screen, workflow etc..?
Thanks,
Maxx
EDIT:
This is the correct answer thanks to Daniel, at the time of this post, this answer is compliant with api 7.3.6
import com.atlassian.jira.bc.project.ProjectCreationData.Builder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.ProjectService
def user = ComponentAccessor.getUserManager().getUserByName('admin')
def projectService = ComponentAccessor.getComponent(ProjectService)
Builder builder = new Builder()
builder.withKey('MAXX23').withName('MAXX23').withLead(user).withDescription('helloworld').withType('business')
def data = builder.build()
def projectResult = projectService.validateCreateProject(user, data)
Project prj = projectService.createProject(projectResult)
return 'finished'