How to create a project with Java?

Hello,

I am trying to create a new project inside of my plugin, but it doesn’t work. Do you have any idea? That’s my function:

                p_NewJiraProjectTypeKey = new ProjectTypeKey("software");

                p_NewJiraProjectCreationDataBuilder = new ProjectCreationData.Builder();

                ProjectCreationData projectCreationData = p_NewJiraProjectCreationDataBuilder
                        .withName(_view1_projectname)
                        .withKey(p_ProjectKey)
                        .withProjectTemplateKey("com.pyxis.greenhopper.jira:basic-software-development-template")
                        .withType(p_NewJiraProjectTypeKey)
                        .withLead(_myClass.getJiraAuthenticationContext().getLoggedInUser())
                        .withAvatarId(p_NewJiraProjectAvatarId)
                        .withAssigneeType(AssigneeTypes.UNASSIGNED)
                        .withDescription(p_NewJiraProjectDescription)
                        .build();

                try {
                    p_NewJiraProject = _myClass.getProjectManager().createProject(_myClass.getJiraAuthenticationContext().getLoggedInUser(), projectCreationData);
                }

It always ends in the catch block (not visible) which only says: “java.lang.IllegalStateException”. Do you have any idea?

Thanks a lot in advance.
Manuel

Hello,

i use this code to create simple project

ProjectService projectService = ComponentAccessor.getComponent(ProjectService.class);
Builder builder = new Builder();
builder.withKey(key);
builder.withName(name);
builder.withLead(leadUser);
builder.withType(typeKey);

ProjectCreationData projectCreationData = builder.build();
ProjectService.CreateProjectValidationResult createProjectValidationResult = projectService.validateCreateProject(applicationUser, projectCreationData);

if( !createProjectValidationResult.isValid() ){
    //check errors and return if exist
}

Project newProject = projectService.createProject(createProjectValidationResult);

Best regards
Adam Labus