当我使用maven创建一个jar文件并使用带有分类器的配置文件时,着色的jar文件在名称中没有分类器。
Maven版本:Apache Maven 3.2.5
以下是其中一个档案:
<profile>
<id>external</id>
<properties>
<envClassifier>external</envClassifier>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<configuration>
<classifier>external</classifier>
</configuration>
<id>external-package</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
但是,目标jar文件没有按照我的预期命名(你可以看到大号阴影jar @ 111MB没有分类名称&#39; external&#39;:
这是我的着色配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<createDependencyReducedPom>true
</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
---removed
</configuration>
</execution>
</executions>
</plugin>
我可以使用shadedArtifactId来强制输出文件的名称,但似乎不需要它。
有什么想法吗?
由于
答案 0 :(得分:2)
根据我的经验,阴影插件会获取主要工件,并将其替换为阴影工件。
如果您希望着色的工件具有分类器,则应将这些配置添加到shade插件中:
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>external</shadedClassifierName>
我不清楚为什么需要配置文件或附加的jar插件配置。我想你可以使用shade插件生成你想要的分类jar。澄清是否有某些要求迫使您使用配置文件。
答案 1 :(得分:0)
所以我能够通过使用finalName属性来实现这一点。如果其他人使用这种技术或者有其他解决方案,那么会对此感到好奇。
public class LikesFeedFragment extends Fragment {
private RecyclerView mBlogList;
private DatabaseReference mDatabase ;
private DatabaseReference mCommentsDatabase;
private Query commentsQuery;
Query recentMessages;
private Query filterLike;
private boolean mProcessLike = false;
private FirebaseAuth auth;
private DatabaseReference mDatabaseLike;
private DatabaseReference ref;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_feed, container, false);
setHasOptionsMenu(true);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");
mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Likes");
mCommentsDatabase = FirebaseDatabase.getInstance().getReference().child("Comentarios");
ref = FirebaseDatabase.getInstance().getReference().child("Likes");
ref.keepSynced(true);
mDatabase.keepSynced(true);
mDatabaseLike.keepSynced(true);
mCommentsDatabase.keepSynced(true);
auth = FirebaseAuth.getInstance();
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot objSnapshot: snapshot.getChildren()) {
String obj = objSnapshot.getKey().toString();
Log.e("Doo 3", obj);
recentMessages = mDatabase.orderByKey().equalTo(obj).limitToLast(20);
}
}
@Override
public void onCancelled(DatabaseError firebaseError) {
Log.e("Read failed", firebaseError.getMessage());
}
});
mBlogList = (RecyclerView) v.findViewById(R.id.blog_list);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
//linearLayoutManager.findFirstVisibleItemPosition();
mBlogList.setHasFixedSize(true);
mBlogList.setLayoutManager(linearLayoutManager);
mBlogList.setNestedScrollingEnabled(false);
return v;
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<FeedData,FeedViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<FeedData, FeedViewHolder>(
FeedData.class,
R.layout.item_feed,
FeedViewHolder.class,
recentMessages) {
@Override
protected void populateViewHolder(final FeedViewHolder viewHolder, FeedData model, int position) {
final String post_key = getRef(position).getKey();
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getContext(), model.getThumb_image());
viewHolder.setLikeBtn(post_key);
commentsQuery = mCommentsDatabase.orderByChild("id_comment").equalTo(post_key);
commentsQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long comentCount = dataSnapshot.getChildrenCount();
if (comentCount == 0) {
viewHolder.comments.setText("0 Comentarios");
}
else {
viewHolder.comments.setText(String.valueOf(comentCount) + " Comentarios");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mDatabaseLike.child(post_key).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long Count = dataSnapshot.getChildrenCount();
// Toast.makeText(getActivity(), (int) Count, Toast.LENGTH_SHORT).show();
Log.e("Doo", String.valueOf(Count));
if (Count == 0) {
viewHolder.likes.setText("0 likes");
// viewHolder.likes.setVisibility(View.INVISIBLE);
}
else {
//viewHolder.likes.setVisibility(View.VISIBLE);
viewHolder.likes.setText(String.valueOf(Count) + " likes");
}
}
@Override
public void onCancelled(DatabaseError databaseError){
}
});
viewHolder.imageBlog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentBlog = new Intent(getActivity(), BlogSingleActivity.class);
intentBlog.putExtra("blog_id",post_key);
startActivity(intentBlog);
}
});
viewHolder.likeButton.setOnLikeListener(new OnLikeListener() {
@Override
public void liked(final LikeButton likeButton) {
mProcessLike = true;
mDatabaseLike.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (mProcessLike) {
if (!dataSnapshot.child(post_key).hasChild(auth.getCurrentUser().getUid())) {
mDatabaseLike.child(post_key).child(auth.getCurrentUser().getUid()).setValue("RandomValue");
likeButton.setLiked(true);
mProcessLike = false;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
@Override
public void unLiked(final LikeButton likeButton) {
mProcessLike = true;
mDatabaseLike.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (mProcessLike) {
if (dataSnapshot.child(post_key).hasChild(auth.getCurrentUser().getUid())) {
mDatabaseLike.child(post_key).child(auth.getCurrentUser().getUid()).removeValue();
likeButton.setLiked(false);
mProcessLike = false;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
public static class FeedViewHolder extends RecyclerView.ViewHolder{
View mView;
LikeButton likeButton;
DatabaseReference mDatabaseLike;
FirebaseAuth mAuth;
ImageView imageBlog;
TextView likes;
TextView comments;
public FeedViewHolder(View itemView) {
super(itemView);
mView = itemView;
likeButton = (LikeButton) mView.findViewById(R.id.heart_button);
imageBlog = (ImageView) mView.findViewById(R.id.imageBlog);
mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Likes");
likes = (TextView) mView.findViewById(R.id.count_like);
comments = (TextView) mView.findViewById(R.id.comentCount);
mAuth = FirebaseAuth.getInstance();
mDatabaseLike.keepSynced(true);
}
public void setLikeBtn(final String post_key){
mDatabaseLike.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())){
likeButton.setLiked(true);
}else{likeButton.setLiked(false);}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
public void setTitle(String title){
TextView post_title = (TextView) mView.findViewById(R.id.post_title);
post_title.setText(title);
}
public void setDesc(String desc){
TextView desc_title = (TextView) mView.findViewById(R.id.post_desc);
desc_title.setText(desc);
}
public void setImage(final Context ctx, final String image) {
// Picasso.with(ctx).load(image).into(imageBlog);
Picasso.with(ctx).load(image).networkPolicy(NetworkPolicy.OFFLINE)
.placeholder(R.drawable.fondonav).into(imageBlog, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
Picasso.with(ctx).load(image).placeholder(R.drawable.fondonav).into(imageBlog);
}
});
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_fragment, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.add) {
Toast.makeText(getActivity(), "Crear publicacion", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getActivity(), PostActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}