Creating a Jar Artifact

It seems my jars are empty.

How do I make them have the "complie module output" definition - same as when i create the artifact manually?

                        Artifact artifact = ArtifactManager.getInstance(project)
                                                  .addArtifact(artifactName,
                                                               JarArtifactType.getInstance(),
                                                               new ArchivePackagingElement(archiveFileName));
               ArtifactImpl artifactImpl = (ArtifactImpl) artifact;
               artifactImpl.setBuildOnMake(true);
               artifactImpl.setOutputPath(libsDir);
                    



Thanks

2 comments

Use PackagingElementFactory.createModuleOutput() to create a 'module output' node and then call
ArtifactManager.addElementsToDirectory(artifact, "/", ...) to add put the created node in an artifact.

By the way it is not recommended to modify artifact properties by casting it to ArtifactImpl and calling setter methods directly.
Instead you should use ArtifactManager.createModifiableModel method, then obtain a modifiable copy of the artifact using
modifiableModel.getOrCreateModifiableArtifact method, set the necessary properties and call modifiableModel.commit().

--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.