Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

maven - How can I solve a conflict when publishing artifacts with classifier to GitHub Packages that share a pom?

tl;dr: I'm trying to solve this issue.

I have a project which builds a platform-dependent JAR and adds a classifier according to the os-maven-plugin:

<modelVersion>4.0.0</modelVersion>
<groupId>com.github.levyfan</groupId>
<artifactId>sentencepiece</artifactId>
<version>0.0.2</version>


<build>
    <extensions>
        <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.6.1</version>
        </extension>
    </extensions>
    <!-- ... -->
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <classifier>${os.detected.classifier}</classifier>
            </configuration>
        </plugin>
    </plugins>
</build>

When I build and publish the artrifact with mvn --batch-mode deploy to GitHub Packages, I'm met with a conflict error. This is because the artifacts share a pom (sentencepiece-0.0.2.pom), but the JAR artifact is determined by the os-maven-plugin value (sentencepiece-0.0.2-XYZ.jar).

How can I inject this plugin-defined property at build-time to create unique artifact names?

question from:https://stackoverflow.com/questions/65901254/how-can-i-solve-a-conflict-when-publishing-artifacts-with-classifier-to-github-p

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let me have a second try.

The items artifactId and version cannot be influenced by plugin generated properties. To influence them, the property must be given on the command line (or maybe in the POM directly).

So we are left with the classifier.

You need to build all artifacts with classifiers in the same build. So you need to change the build in a way that it builds for the different OS in one go. I don't know whether that is possible (depending on whether you can build e.g. for Windows on Linux) but it seems to be the only "Maven way" solution for you problem.

Of course, you could still try tricks like deleting the POM after you have deployed it, but if possible this should be avoided.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...