'How to fix Intellij idea not adding manifest to Artifact?

I ran into a problem which I cannot solve neither by cleaning, nor by deleting Artifact/recreating it. I stuck with it for several days now and google search doesn't know such problem.

So, I have a Gradle java project in Intellij Idea, and it doesn't extract my manifest to Artifact's jar.

It does it in a different project, but here it doesn't include manifest, so my jar says no main manifest attribute, in txtadventureserver_main.jar

enter image description here

Here's the Artifact screen - manifest is not there and I don't see how I add it

enter image description here

here's my gradle:

group 'com.vladdrummer.txtadventureserver'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8

jar {
    manifest {
        attributes 'Main-Class': 'TextAdventureServer'
    }
}
repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile "com.sparkjava:spark-core:2.7.2"
}


Solution 1:[1]

I had a similar problem: I selected my own manifest.mf but artifact-manager apparently choosed the first manifest.mf from dependencies.

I solved in the following way (it's just a workaround, of course):

I edited <MyProject>/.idea/artifacts/<MyProject>.xml

<component name="ArtifactManager">
  <artifact type="jar" build-on-make="true" name="MyProject">
    <output-path>$PROJECT_DIR$/out/artifacts/MyProject</output-path>
    <root id="archive" name="myproject.jar">
      <element id="module-output" name="MyProject" />
      <element id="module-output" name="CmdLineArgsUtil" />
      <element id="extracted-dir" path="$PROJECT_DIR$/../libs/mylib-1.2.0.jar" path-in-jar="/" />
      <element id="directory" name="META-INF">
        <element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
      </element>
    </root>
  </artifact>
</component>

and moved node "META-INF" immediately after node "MyProject" as in the following example:

<component name="ArtifactManager">
  <artifact type="jar" build-on-make="true" name="MyProject">
    <output-path>$PROJECT_DIR$/out/artifacts/MyProject</output-path>
    <root id="archive" name="myproject.jar">
      <element id="module-output" name="MyProject" />
      <element id="directory" name="META-INF">
        <element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
      </element>
      <element id="module-output" name="CmdLineArgsUtil" />
      <element id="extracted-dir" path="$PROJECT_DIR$/../libs/mylib-1.2.0.jar" path-in-jar="/" />
    </root>
  </artifact>
</component>

Solution 2:[2]

You can generate the MANIFEST.mf by going here in the Project Settings window:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marco S.
Solution 2 Bajal