Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ed02d02d
Commit
ed02d02d
authored
May 15, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Allow repackage maven goal to take a source classifier"
Closes gh-11061
parent
3c8e0124
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
216 additions
and
49 deletions
+216
-49
verify.groovy
...oot-maven-plugin/src/it/jar-attach-disabled/verify.groovy
+1
-1
invoker.properties
...aven-plugin/src/it/jar-classifier-main/invoker.properties
+1
-0
pom.xml
...ring-boot-maven-plugin/src/it/jar-classifier-main/pom.xml
+57
-0
SampleApplication.java
...sifier-main/src/main/java/org/test/SampleApplication.java
+7
-9
verify.groovy
...oot-maven-plugin/src/it/jar-classifier-main/verify.groovy
+20
-0
invoker.properties
...en-plugin/src/it/jar-classifier-source/invoker.properties
+1
-0
pom.xml
...ng-boot-maven-plugin/src/it/jar-classifier-source/pom.xml
+1
-1
SampleApplication.java
...fier-source/src/main/java/org/test/SampleApplication.java
+0
-0
verify.groovy
...t-maven-plugin/src/it/jar-classifier-source/verify.groovy
+33
-0
RepackageMojo.java
...in/java/org/springframework/boot/maven/RepackageMojo.java
+38
-36
repackage-classifier.apt.vm
...-plugin/src/site/apt/examples/repackage-classifier.apt.vm
+57
-2
No files found.
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-attach-disabled/verify.groovy
View file @
ed02d02d
...
@@ -13,7 +13,7 @@ assertTrue 'backup file should exist', backup.exists()
...
@@ -13,7 +13,7 @@ assertTrue 'backup file should exist', backup.exists()
def
file
=
new
File
(
basedir
,
"build.log"
)
def
file
=
new
File
(
basedir
,
"build.log"
)
assertTrue
'main artifact should have been updated'
,
assertTrue
'main artifact should have been updated'
,
file
.
text
.
contains
(
"Updating
main
artifact "
+
main
+
" to "
+
backup
)
file
.
text
.
contains
(
"Updating artifact "
+
main
+
" to "
+
backup
)
return
file
.
text
.
contains
(
"Installing "
+
backup
)
return
file
.
text
.
contains
(
"Installing "
+
backup
)
...
...
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-classifier-main/invoker.properties
0 → 100644
View file @
ed02d02d
invoker.goals
=
clean install
\ No newline at end of file
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-classifier-main/pom.xml
0 → 100644
View file @
ed02d02d
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.springframework.boot.maven.it
</groupId>
<artifactId>
jar-classifier-main
</artifactId>
<version>
0.0.1.BUILD-SNAPSHOT
</version>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
@java.version@
</maven.compiler.source>
<maven.compiler.target>
@java.version@
</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>
@project.groupId@
</groupId>
<artifactId>
@project.artifactId@
</artifactId>
<version>
@project.version@
</version>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
<configuration>
<classifier>
test
</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
<version>
@maven-jar-plugin.version@
</version>
<configuration>
<archive>
<manifestEntries>
<Not-Used>
Foo
</Not-Used>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
<version>
@spring.version@
</version>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
@servlet-api.version@
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-
repackage-classifier/verify.groovy
→
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-
classifier-main/src/main/java/org/test/SampleApplication.java
View file @
ed02d02d
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -14,13 +14,11 @@
...
@@ -14,13 +14,11 @@
* limitations under the License.
* limitations under the License.
*/
*/
import
java.io.*
;
package
org
.
test
;
import
org.springframework.boot.maven.*
;
File
f
=
new
File
(
basedir
,
"target/jar-repackage-classifier-0.0.1.BUILD-SNAPSHOT-test.jar"
);
public
class
SampleApplication
{
new
Verify
.
JarArchiveVerification
(
f
,
Verify
.
SAMPLE_APP
)
{
@Override
public
static
void
main
(
String
[]
args
)
{
protected
void
verifyZipEntries
(
Verify
.
ArchiveVerifier
verifier
)
throws
Exception
{
super
.
verifyZipEntries
(
verifier
)
}
}
}.
verify
();
}
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-classifier-main/verify.groovy
0 → 100644
View file @
ed02d02d
import
java.io.*
;
import
org.springframework.boot.maven.*
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
File
repackaged
=
new
File
(
basedir
,
"target/jar-classifier-main-0.0.1.BUILD-SNAPSHOT-test.jar"
)
new
Verify
.
JarArchiveVerification
(
repackaged
,
Verify
.
SAMPLE_APP
).
verify
();
File
main
=
new
File
(
basedir
,
"target/jar-classifier-main-0.0.1.BUILD-SNAPSHOT.jar"
)
assertTrue
'main artifact should exist'
,
main
.
exists
()
File
backup
=
new
File
(
basedir
,
"target/jar-classifier-main-0.0.1.BUILD-SNAPSHOT.jar.original"
)
assertFalse
'backup artifact should not exist'
,
backup
.
exists
()
def
file
=
new
File
(
basedir
,
"build.log"
)
assertTrue
'repackaged artifact should have been attached'
,
file
.
text
.
contains
(
"Attaching archive "
+
repackaged
)
assertTrue
'main artifact should have been installed'
,
file
.
text
.
contains
(
"Installing "
+
main
)
assertTrue
'repackaged artifact should have been installed'
,
file
.
text
.
contains
(
"Installing "
+
repackaged
)
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-classifier-source/invoker.properties
0 → 100644
View file @
ed02d02d
invoker.goals
=
clean install
\ No newline at end of file
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-
repackage-classifier
/pom.xml
→
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-
classifier-source
/pom.xml
View file @
ed02d02d
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.springframework.boot.maven.it
</groupId>
<groupId>
org.springframework.boot.maven.it
</groupId>
<artifactId>
jar-
repackage-classifier
</artifactId>
<artifactId>
jar-
classifier-source
</artifactId>
<version>
0.0.1.BUILD-SNAPSHOT
</version>
<version>
0.0.1.BUILD-SNAPSHOT
</version>
<properties>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
...
...
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-
repackage-classifier
/src/main/java/org/test/SampleApplication.java
→
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-
classifier-source
/src/main/java/org/test/SampleApplication.java
View file @
ed02d02d
File moved
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-classifier-source/verify.groovy
0 → 100644
View file @
ed02d02d
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
java.io.*
;
import
org.springframework.boot.maven.*
import
static
org
.
junit
.
Assert
.
assertFalse
import
static
org
.
junit
.
Assert
.
assertTrue
;
File
repackaged
=
new
File
(
basedir
,
"target/jar-classifier-source-0.0.1.BUILD-SNAPSHOT-test.jar"
);
new
Verify
.
JarArchiveVerification
(
repackaged
,
Verify
.
SAMPLE_APP
).
verify
();
File
backup
=
new
File
(
basedir
,
"target/jar-classifier-source-0.0.1.BUILD-SNAPSHOT-test.jar.original"
)
assertTrue
'backup artifact should exist'
,
backup
.
exists
()
def
file
=
new
File
(
basedir
,
"build.log"
)
assertTrue
'repackaged artifact should have been replaced'
,
file
.
text
.
contains
(
"Replacing artifact with classifier test "
+
repackaged
)
assertFalse
'backup artifact should not have been installed'
,
file
.
text
.
contains
(
"Installing "
+
backup
)
assertTrue
'repackaged artifact should have been installed'
,
file
.
text
.
contains
(
"Installing "
+
repackaged
)
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java
View file @
ed02d02d
...
@@ -98,12 +98,13 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
...
@@ -98,12 +98,13 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
private
boolean
skip
;
private
boolean
skip
;
/**
/**
* Classifier to add to the artifact generated. If given, the artifact will be
* Classifier to add to the repackaged archive. If not given, the main artifact will
* attached with that classifier and the main artifact will be deployed as the main
* be replaced by the repackaged archive. If given, the classifier will also be used
* artifact. If an artifact with the classifier already exists, it will be used as source.
* to determine the source archive to repackage: if an artifact with that classifier
* If a classifier is not given (default), it will replace the main artifact and
* already exists, it will be used as source and replaced. If no such artifact exists,
* only the repackaged artifact will be deployed. Attaching the artifact allows to
* the main artifact will be used as source and the repackaged archive will be
* deploy it alongside to the original one, see <a href=
* attached as a supplemental artifact with that classifier. Attaching the artifact
* allows to deploy it alongside to the original one, see <a href=
* "http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html"
* "http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html"
* > the maven documentation for more details</a>.
* > the maven documentation for more details</a>.
* @since 1.0
* @since 1.0
...
@@ -210,9 +211,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
...
@@ -210,9 +211,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
}
}
private
void
repackage
()
throws
MojoExecutionException
{
private
void
repackage
()
throws
MojoExecutionException
{
File
source
=
getSourceFile
();
Artifact
source
=
getSourceArtifact
();
File
target
=
getTargetFile
();
File
target
=
getTargetFile
();
Repackager
repackager
=
getRepackager
(
source
);
Repackager
repackager
=
getRepackager
(
source
.
getFile
()
);
Set
<
Artifact
>
artifacts
=
filterDependencies
(
this
.
project
.
getArtifacts
(),
Set
<
Artifact
>
artifacts
=
filterDependencies
(
this
.
project
.
getArtifacts
(),
getFilters
(
getAdditionalFilters
()));
getFilters
(
getAdditionalFilters
()));
Libraries
libraries
=
new
ArtifactsLibraries
(
artifacts
,
this
.
requiresUnpack
,
Libraries
libraries
=
new
ArtifactsLibraries
(
artifacts
,
this
.
requiresUnpack
,
...
@@ -227,19 +228,26 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
...
@@ -227,19 +228,26 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
updateArtifact
(
source
,
target
,
repackager
.
getBackupFile
());
updateArtifact
(
source
,
target
,
repackager
.
getBackupFile
());
}
}
private
File
getSourceFile
()
{
/**
Artifact
sourceArtifact
=
this
.
project
.
getArtifact
();
* Return the source {@link Artifact} to repackage. If a classifier is specified
* and an artifact with that classifier exists, it is used. Otherwise, the main
* artifact is used.
* @return the source artifact to repackage
*/
private
Artifact
getSourceArtifact
()
{
Artifact
sourceArtifact
=
getArtifact
(
this
.
classifier
);
return
(
sourceArtifact
!=
null
?
sourceArtifact
:
this
.
project
.
getArtifact
());
}
if
(
this
.
classifier
!=
null
)
{
private
Artifact
getArtifact
(
String
classifier
)
{
if
(
classifier
!=
null
)
{
for
(
Artifact
attachedArtifact
:
this
.
project
.
getAttachedArtifacts
())
{
for
(
Artifact
attachedArtifact
:
this
.
project
.
getAttachedArtifacts
())
{
if
(
this
.
classifier
.
equals
(
attachedArtifact
.
getClassifier
()))
{
if
(
classifier
.
equals
(
attachedArtifact
.
getClassifier
()))
{
sourceArtifact
=
attachedArtifact
;
return
attachedArtifact
;
break
;
}
}
}
}
}
}
return
null
;
return
sourceArtifact
.
getFile
();
}
}
private
File
getTargetFile
()
{
private
File
getTargetFile
()
{
...
@@ -250,18 +258,10 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
...
@@ -250,18 +258,10 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
if
(!
this
.
outputDirectory
.
exists
())
{
if
(!
this
.
outputDirectory
.
exists
())
{
this
.
outputDirectory
.
mkdirs
();
this
.
outputDirectory
.
mkdirs
();
}
}
return
new
File
(
this
.
outputDirectory
,
this
.
finalName
+
getClassifier
()
+
"."
return
new
File
(
this
.
outputDirectory
,
this
.
finalName
+
classifier
+
"."
+
this
.
project
.
getArtifact
().
getArtifactHandler
().
getExtension
());
+
this
.
project
.
getArtifact
().
getArtifactHandler
().
getExtension
());
}
}
private
String
getClassifier
()
{
String
classifier
=
(
this
.
classifier
==
null
?
""
:
this
.
classifier
.
trim
());
if
(
classifier
.
length
()
>
0
&&
!
classifier
.
startsWith
(
"-"
))
{
classifier
=
"-"
+
classifier
;
}
return
classifier
;
}
private
Repackager
getRepackager
(
File
source
)
{
private
Repackager
getRepackager
(
File
source
)
{
Repackager
repackager
=
new
Repackager
(
source
,
this
.
layoutFactory
);
Repackager
repackager
=
new
Repackager
(
source
,
this
.
layoutFactory
);
repackager
.
addMainClassTimeoutWarningListener
(
repackager
.
addMainClassTimeoutWarningListener
(
...
@@ -327,26 +327,28 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
...
@@ -327,26 +327,28 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
}
}
}
}
private
void
updateArtifact
(
File
source
,
File
repackaged
,
File
original
)
{
private
void
updateArtifact
(
Artifact
source
,
File
target
,
File
original
)
{
if
(
this
.
attach
)
{
if
(
this
.
attach
)
{
attachArtifact
(
source
,
repackaged
);
attachArtifact
(
source
,
target
);
}
}
else
if
(
source
.
equals
(
repackaged
))
{
else
if
(
source
.
getFile
().
equals
(
target
))
{
getLog
().
info
(
"Updating artifact "
+
source
.
getFile
()
+
" to "
+
original
);
this
.
project
.
getArtifact
().
setFile
(
original
);
this
.
project
.
getArtifact
().
setFile
(
original
);
getLog
().
info
(
"Updating main artifact "
+
source
+
" to "
+
original
);
}
}
}
}
private
void
attachArtifact
(
File
source
,
File
repackaged
)
{
private
void
attachArtifact
(
Artifact
source
,
File
target
)
{
if
(
this
.
classifier
!=
null
)
{
if
(
this
.
classifier
!=
null
&&
!
source
.
getFile
().
equals
(
target
)
)
{
getLog
().
info
(
"Attaching archive
: "
+
repackaged
+
", with classifier:
"
getLog
().
info
(
"Attaching archive
"
+
target
+
" with classifier
"
+
this
.
classifier
);
+
this
.
classifier
);
this
.
projectHelper
.
attachArtifact
(
this
.
project
,
this
.
project
.
getPackaging
(),
this
.
projectHelper
.
attachArtifact
(
this
.
project
,
this
.
project
.
getPackaging
(),
this
.
classifier
,
repackaged
);
this
.
classifier
,
target
);
}
}
else
if
(!
source
.
equals
(
repackaged
))
{
else
{
this
.
project
.
getArtifact
().
setFile
(
repackaged
);
String
artifactId
=
this
.
classifier
!=
null
getLog
().
info
(
"Replacing main artifact "
+
source
+
" to "
+
repackaged
);
?
"artifact with classifier "
+
this
.
classifier
:
"main artifact"
;
getLog
().
info
(
String
.
format
(
"Replacing %s %s"
,
artifactId
,
source
.
getFile
()));
source
.
setFile
(
target
);
}
}
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/repackage-classifier.apt.vm
View file @
ed02d02d
...
@@ -47,9 +47,64 @@
...
@@ -47,9 +47,64 @@
</project>
</project>
---
---
This configuration will generate two artifacts: the original one and the repackaged counter
This configuration will generate two artifacts: the original one and the repackaged
part produced by the repackage goal. Both will be installed/deployed transparently.
counter part produced by the repackage goal. Both will be installed/deployed
transparently.
You can also use the same configuration if you want to repackage a secondary artifact
the same way the main artifact is replaced. The following configuration installs/deploys
a single <<<task>>> classified artifact with the repackaged app:
---
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>@maven-jar-plugin.version@</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>task</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>task</classifier>
</configuration>
</execution>
</executions>
...
</plugin>
...
</plugins>
...
</build>
...
</project>
---
As both the <<<maven-jar-plugin>>> and the <<<spring-boot-maven-plugin>>> runs at the
same phase, it is important that the jar plugin is defined first (so that it runs before
the repackage goal).
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment